Year 1 · Week 11
Chapter 11: Python Fundamentals Test
This test covers everything you have learned in Python from Week 01 through Week 10. For each question, figure out your answer first, then click "Show Answer" to check. There are 28 questions across five sections.
Section 1: Built-in Functions (4 questions)
Q1. What does this code print?
print( int("42") )
Show Answer
42
int("42") converts the string "42" to the integer 42, then print displays it.
Q2. What does this code print?
print( type(3.14) )
Show Answer
<class 'float'>
3.14 has a decimal point, so Python treats it as a float.
Q3. What does this code print?
print( len([10, 20, 30]) )
Show Answer
3
len() returns the number of items in the list. This list has three items.
Q4. What does this code print?
print( str(100) + str(200) )
Show Answer
100200
str(100) is the string "100", and str(200) is "200". The + operator on strings concatenates them — it does not add mathematically.
Section 2: Variable Types (4 questions)
Q5. After this code runs, what is the type and value of x?
x = 7 / 2
Show Answer
Type: float, value: 3.5
In Python, / always returns a float, even when both operands are integers.
Q6. What does this code print?
name = "LEGO" print(name * 3)
Show Answer
LEGOLEGÓLEGO
Multiplying a string by an integer repeats the string that many times.
Q7. What does this code print?
a = True b = False print(a + b)
Show Answer
1
In Python, True equals 1 and False equals 0. So True + False = 1 + 0 = 1.
Q8. What is wrong with this code?
age = "12" print(age + 3)
Show Answer
TypeError — you cannot use + to add a string and an integer.
age is the string "12", not the number 12. Fix: print(int(age) + 3), which prints 15.
Section 3: For Loops (4 questions)
Q9. What does this code print?
for i in range(4): print(i)
Show Answer
Four lines of output:
0 1 2 3
range(4) produces 0, 1, 2, 3 (starts at 0, stops before 4). Each loop iteration prints one number.
Q10. What does this code print?
total = 0 for n in [3, 5, 7]: total = total + n print(total)
Show Answer
15
The loop adds each number to total: 0 → 3 → 8 → 15.
Q11. Write a for loop that prints every even number from 0 to 8.
Show Answer
for i in range(5): print(i * 2)
Output: 0, 2, 4, 6, 8 — each on its own line. The loop goes from 0 to 4, and multiplying by 2 gives even numbers.
Q12. What does this code print?
words = ["hello", "world"] for word in words: for i in range(2): print(word)
Show Answer
Four lines of output:
hello hello world world
The outer loop goes through the two words. For each word, the inner loop prints it twice.
Section 4: If / Else (4 questions)
Q13. What does this code print?
x = 15 if x > 20: print("big") elif x > 10: print("medium") else: print("small")
Show Answer
medium
x = 15 is not greater than 20, but it is greater than 10, so the elif branch runs.
Q14. What does this code print?
temp = 0 print(temp > 0 or temp == 0)
Show Answer
True
temp > 0 is False, but temp == 0 is True. With or, only one side needs to be True for the whole expression to be True.
Q15. Write an if/elif/else that prints "hot" if temp is greater than 30, "warm" if greater than 15, and "cold" otherwise.
Show Answer
if temp > 30: print("hot") elif temp > 15: print("warm") else: print("cold")
Using elif chains the conditions — Python checks top to bottom and runs only the first branch that is True, skipping the rest.
Q16. What does this code print? Look carefully!
score = 85 if score >= 90: grade = "A" if score >= 80: grade = "B" if score >= 70: grade = "C" print(grade)
Show Answer
C
This code uses three separate if statements, not elif! Each one is checked independently. With score = 85: the first if (≥ 90) is false; the second if (≥ 80) is true, setting grade = "B"; the third if (≥ 70) is also true, overwriting grade to "C". Using elif would fix this.
Section 5: Functions (12 questions)
Q17. What does this code print?
def double(x): return x * 2 print(double(5))
Show Answer
10
double(5) returns 5 * 2 = 10, and print displays it.
Q18. What does this code print?
def greet(name): print("Hello " + name) result = greet("Spike") print(result)
Show Answer
Two lines of output:
Hello Spike None
greet uses print inside to display Hello Spike, but it has no return statement, so its return value is None. That's what gets stored in result.
Q19. Write a function add(a, b) that returns the sum of a and b.
Show Answer
def add(a, b): return a + b
Q20. What does this code print?
def square(n): return n * n print(square(3) + square(4))
Show Answer
25
square(3) = 9, square(4) = 16, and 9 + 16 = 25.
Q21. What is wrong with this function?
def subtract(a, b): a - b print(subtract(10, 3))
Show Answer
It prints None. The function computes a - b but never uses return to send the result back.
Fix: return a - b — then it would print 7.
Q22. Given this code, what does small_drive_mid(90) return?
SMALL_GEAR = 12 MID_GEAR = 20 def small_drive_mid(degree): return int(degree * MID_GEAR / SMALL_GEAR)
Show Answer
150
int(90 * 20 / 12) = int(150.0) = 150. To get the mid gear to turn 90 degrees, the motor must spin the small gear 150 degrees.
Q23. Given MID_GEAR = 20 and BIG_GEAR = 28, write a function mid_drive_big(degree) that calculates how far the mid gear must turn to get the big gear to turn degree degrees.
Show Answer
def mid_drive_big(degree): return int(degree * BIG_GEAR / MID_GEAR)
Formula: driver degrees = desired output degrees × driven teeth ÷ driver teeth.
Q24. What does this code print?
def add_one(x): return x + 1 print( add_one(add_one(3)) )
Show Answer
5
Inside out: add_one(3) = 4, then add_one(4) = 5. This is function composition.
Q25. Using the small_drive_mid function from Q22, what does small_drive_mid(small_drive_mid(12)) return?
Show Answer
33
Step 1: small_drive_mid(12) = int(12 * 20 / 12) = 20
Step 2: small_drive_mid(20) = int(20 * 20 / 12) = int(33.33) = 33
Q26. Write a function bigger(a, b) that returns the larger of the two numbers.
Show Answer
def bigger(a, b): if a > b: return a else: return b
Use if/else to compare the two numbers and return the larger one.
Q27. What does this code print?
def mystery(a, b): if a > b: return a else: return b print(mystery(7, 12))
Show Answer
12
7 > 12 is False, so the else branch returns b = 12. This function is equivalent to the built-in max(a, b).
Q28. Read the function below. What does gear_ratio(90, 12, 20) return? What does this function do?
def gear_ratio(input_deg, driver_teeth, driven_teeth): return int(input_deg * driven_teeth / driver_teeth)
Show Answer
It returns 150. int(90 * 20 / 12) = int(150.0) = 150.
This function calculates how far the driver gear must turn to get the driven gear to turn input_deg degrees. It's a general-purpose version that replaces small_drive_mid, mid_drive_small, and all the others — just pass in different tooth counts.