This is the name of the dog we program in the early units of Codehs.
What is Karel?
Which operator does this : True or False
What is a boolean (or boolean value)?
These operators (==, !=, <, >, <=, >=) compare two values and always produce a boolean result.
What are comparison operators?
This is the name we give to a storage location that holds a value in a program.
What is a variable?
This command is used to display text or values on the screen.
What is print()?
This Karel command moves Karel one spot forward in the direction he's facing.
What is move()?
This is a keyword used to start a conditional statement that only runs its indented code when a condition is true.
What is if?
What does the following expression evaluate to?
7 > 3 and 2 < 2
What is False?
What will this code print?
name = "Alex"
print(name)
print(name)
print(name)
print(name)
print(name)
print(name)
The code will print "Alex" 7 times.
What does the * operator do when used between a string and an integer? (Example: "Hi" * 3)
What is string repetition? (It repeats that string that many times).
What does this Karel function do? (Karel is facing West).
turn_right()
turn_left()
turn_left()
turn_right()
Karel turns in the West direction.
What will this code print?
has_homework = True
is_weekend = False
if has_homework:
if is_weekend:
print("Do it later.")
else:
print("Do it now.")
print("Done checking.")
The program will print "Do it now." followed by "Done checking."
The logical operator returns True only when both conditions on either side of it are true.
What is "and"?
Fix the error in this code so it correctly calculates the user's age next year and prints it as a number:
age = input("Enter your age: ")
print("Next year you will be " + age + 1)
Convert age to an integer before adding 1 to it. And the user input line of code inside an "int" parentheses.
What is the result of this expression?
10//3
3, (integer division/floor division).
Karel is facing East, after the following code runs, witch direction is Karel facing?
turn_left()
turn_left()
move()
turn_left()
What is South?
This keyword allows you to check a second condition only if the first if condition was false.
What is "elif"?
What will this code print?
score = 82
if score >= 90:
print("A")
elif score >= 80:
print("B")
else:
print("C")
What is "B"?
What will this code print? (Assume that the user enters 5).
num = (input("Enter a number: ")
print(num * 3)
555, because we didn't put the user input line of code inside an "int" parentheses, and so the user input is treated like a string instead of a number!
What will this code print?
x = 5
y = "3"
print(x * int(y))
print(str(x) + y)
15
53
Karel starts in a 5x5 world at Avenue 1, Street 1, facing East. After this code runs, on which avenue and street is Karel on? And which direction is he facing?
def turn_right():
turn_left()
turn_left()
turn_left()
move()
turn_left()
move()
turn_right()
move()
turn_left()
turn_left()
Avenue 2, Street 2, facing West.
What is wrong with this code, and what will happen when it runs?
age = 16
if age >= 18
print("You can vote.")
else:
print("You cannot vote.")
A missing colon after the if condition. And if the program runs, a syntax error will occur.
Explain why this comparison may not work the way a student expects, and name the concept it demonstrates:
if 0.1 + 0.2 == 0.3:
print("Equal.")
else:
print("Not equal.")
What is floating-point rounding error (or floating-point precision/imprecision)? (It prints "Not equal." because of how floating point numbers are stored.)
A student wrote this program and is confused why it doesn't work correctly. Explain the two problems and how to fix them:
age = input("How old are you? ")
next_year = age + 1
print("Next year you will be " + next_year)
1) age is a string, so you cannot add 1 to it (must convert it to an integer first).
2) After converting, next_year becomes an integer, so you must convert it back to a string before concatenating.
Explain the difference between / and // in Python, and give the result of both for 7/2 and 7//2.
/ does true division (result is 3.5), while // does integer/floor division (result is 3).