Nesting
The process of placing code inside another command. Four spaces or one tab.
stage_image = stage_list[1]
Stores the second item in stage_list as the value of stage_image
Orange
Variables
my_display = codesters.Display(rand_num, -0, 0)
Displays the value of rand_num at 0, 0
def whiskers():
tiger.glide_to(50, -150)
stage.wait(2)
whiskers.say("Meow.")
stage.wait(2)
whiskers.say("Meow. Meow.")
stage.wait(2)
whiskers.say("Meow.")
tiger.flip_right_left()
tiger.say("mew, mew")
tiger.glide_to(300, -150)
whiskers()
Variable names and function names can't be the same
Function
Contains a block of code that can be called at any point later in the program, any number of times
timer *= 0.8
Multiplies timer by 0.8
Blue
Integers and Floats
savings = sum(coins)
Stores the total value of all the items in coins inside of savings
rainbow = ["red", "orange", "yellow", "green", "black"]
index = rainbow.index(5)
Index start with 0. This command is asking for the 6th item in a 5 item list.
While loop
Runs until a condition is met or a specific value is held inside the test variable
random.randint(1, 10)
Generates a random number between 1 and 10.
Grey
Comment Code
if "#" not in hidden_list:
Runs the code nested inside if there is not # in hidden_list
def 3laps():
stage.set_background("soccerfield")
sprite.say("I try to practice every day.")
sprite.move_left(200)
sprite.move_right(400)
sprite.move_left(400)
sprite.move_right(400)
sprite.move_left(400)
sprite.move_right(200)
3laps()
Function names can't start with a number
Index
The position of an item in a list
list.append("shark")
Adds a shark sprite to the end of the list.
Green
Strings
purpose.split()
Splits the value stored in purpose into a list of individual letters
to_do = ["finish homework", "clean room", "practice instrument"]
my_list.remove("finish homework")
Remove command is assigned to my_list instead of to_do
console
a programming environment that only inputs & outputs text
len()
Calculates the length of a sting or list.
White
Dot Notation
str(quotient)
Converts the value of quotient to a string
def number_generator():
rand_num = random.randint(1,100)
return rand_num
my_display = codesters.Display(rand_num, 0, 150)
There is no return variable storing the value created in the function. See correct code below
def number_generator():
rand_num = random.randint(1,100)
return rand_num
my_num = number_generator()
my_display = codesters.Display(my_num, 0, 150)