Count to 10 using a for loop
for i in range(1,11):
write(i)
What does this write?
var teacher = "Mr. Kleinscroth"
write(teacher.to_lower())
"mr. kleinscroth'
var word = "GODOT". What is word[1]?
"O"
Describe how a while loop works
Create an empty array (list)
var array = []
What does this write?
for i in range(2, 10, 3):
write(str(i))
2, 5, 8
What does "Minecraft".length() return?
9
What does this write?
var word = "GODOT"
for letter in word:
write(letter)
G
O
D
O
T
How do you stop this while loop?
var is_alive = true
var health = 100
var score = 0
while is_alive:
score = score + 1
...
health = 0
is_alive = false
What does fruits[3] write? ["Banana", "Apple", "Orange", "Pineapple", "Cherry"]
"Pineapple"
Why does this code fail?
var list = ["Minecraft", "Roblox", "CS2", "Flappy bird"]
for i in range(list.size()):
if print(i)
IndexError index out of range as size returns the number of items in the list but the highest index of the list is list.size()-1.
What does this write?
var fruits = "apple,banana,cherry"
write(fruits.split(",")[1])
"banana"
What does "GODOT".substr(1, 3) return?
"ODO"
Why does this loop never end?
var count = 0
while count < 5:
write(str(count))
Count never changes so count will always be less than 5
What happens when you run write(city[4])? city = ["Toronto", "New York", "Tokyo", "Paris"]
Error (bonus points for IndexError, index out of range)
How many times does "hi" get written?
for i in range(3):
for j in range(4):
write("hi")
12
What does this return?
"I like cats".replace("cats", "dogs").to_upper()
"I LIKE DOGS"
Write code that writes "Hello" backwards ("olleH")
write(word.reverse())
var word = "GODOT"
var result = ""
for i in range(word.length() - 1, -1, -1):
result += word[i]
write(result)
What does this write?
var x = 1
while x < 20:
x = x * 2
write(str(x))
32
var list = ["John", "Jane", "David", "Luke"]
for name in list:
write(name+"! " + str(randi_range(1,10)))
John! random number from 1-10
Jane! random number from 1-10
David! random number from 1-10
Luke! random number from 1-10
Write a for loop that adds up every number from 1 to 50 and writes the total
var total = 0
for i in range(1, 101):
total += i
write(str(total))
How would you evaluate the user's answer as no for "Nah", "no", "No", "noooo ", "nah", " nope"?
Starting code:
var answer = input()
Many answers:
var answer = input()
if answer.to_upper().strip_edges().begins_with("N"):
write("No")
elif answer.to_upper().strip_edges().begins_with("Y"):
write("Yes")
else:
write("Invalid input")
Write one line of code that writes the last letter without counting the letters yourself.
E.g. var name = "Tab" -> writes "b"
var name = "Kleinscroth" -> writes "h"
write(name[name.length() - 1])
write(name[-1])
Write a while loop that prints out every letter in "Godot"
var word = "Godot"
var i = 0
while i < word.length()-1:
write(word[i])
var list = ["Canada", "US", "Congo", "Sweden"]
list.append("Gabon")
new_list = list[3]
write(list[4])
"Gabon"