This repository was archived by the owner on Jan 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusercode.py
More file actions
45 lines (42 loc) · 2.63 KB
/
usercode.py
File metadata and controls
45 lines (42 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"""
Write out the code:
def level_1():
return 'Hello, world!'
The `def hello_world()`, a function definition, tells the computer that all lines of code indented under it are instructions describing how to run the function `level_1()`. The `return 'Hello, world!'` tells the computer to give the text `'Hello, world!'` to the program that is tasked with running this code. This text is usually called a string.
Make sure to get rid of the `pass` statement in your code.
"""
def level_1():
pass
"""
Now it's time for variables! A variable in Python is a changeable value stored under a particular name. For example, the variable `foo` might be storing the string `'bar'`. We don't have to know what each variable is holding; we can use variable names *without* quotes in place of any string, and the computer will automatically replace the variable name with whatever is stored inside that variable.
You can accept input as a variable (name the variable whatever you want) by putting a variable name inside the parentheses of the function definition.
"""
def level_2(arg):
pass
"""Alright, integers. Integers are numbers, positive, negative, or zero, with no fractional part. In Python, integers are notated by just the number itself; in other words, you don't need quotes or anything, unlike strings. Just like strings, however, integers can be stored in variables. They can also be operated on. For example, `2 + 3` is actually acceptable Python code that evaluates to `5` (`return 2 + 3` will just return `5`).
"""
def level_3(arg):
pass
"""Conditionals! Conditionals, or `if` statements, run different code based on whether something is `True` or `False`. `True` and `False` are actually Python keywords. They are called boolean values. A variable can be assigned a boolean value, so `foo = True` is valid code. An `if` statement is written like so:
if a:
<Your code here for if `a` is `True`>
elif !a:
<Your code here for if `a` is `False`>
elif b == 'Hello':
<Your code here for if `b` is `'Hello'`>
elif b != 'Hello':
<Your code here for if `b` is *not* `'Hello'`>
elif c == 4:
<Your code here for if `c` is `4`>
elif c > 5:
<Your code here for if `c` is greater than `5`>
elif c <= 3:
<Your code here for if `c` is less than or equal to `3`>
elif c != 2:
<Your code here for if `c` is *not* `2`>
else:
<Your code here for if none of the above conditions work>
In this example, `a`, `b`, and `c` are variables. You do not have to include all of these components in an `if` statement, so only check for what is necessary.
"""
def level_4(arg):
pass