๐งช Final Challenge
The exam covering all twelve modules. 15 questions, no peeking at earlier lessons. Write your answers before checking the solutions โ the gap between "I think I know" and "I typed it" is the entire course.
Section 1: Foundations (Modules 1โ2)
Q1. Who created Python, and why the name?
Q2. Identify every token type in: score = score + 10
Q3. Which are legal identifiers: my-score, _temp, class, Class2, 7up?
Section 2: Variables & Operators (Modules 3โ4)
Q4. What does this print?
x = "5"
y = 5
print(x == y, x + "!", y * 2)Q5. What does this print?
n = 17
print(n % 5, n // 5, 2 ** 3)Q6. One line each โ check whether:
a) word contains "py" (case-insensitive)
b) x is between 1 and 100 (inclusive)
Section 3: Data Structures (Module 5)
Q7. Given data = {"a": [1, 2], "b": [3]} โ write the line that prints 3.
Q8. Remove all duplicates from [1, 3, 1, 2, 3, 1] in one line, preserving the ability to loop it.
Section 4: Control Flow & Functions (Modules 6โ7)
Q9. Write fizzbuzz(n) โ returns "Fizz" (divisible by 3), "Buzz" (by 5), "FizzBuzz" (both), or the number as a string.
Q10. Fix this function so result holds 30:
def double(x):
print(x * 2)
result = double(15)Q11. What does this print?
def modify(lst):
lst.append(99)
nums = [1, 2]
modify(nums)
print(nums)Section 5: Errors, Files & OOP (Modules 8โ9)
Q12. Write the except block that safely handles a user typing "abc" into int(input(...)).
Q13. Load scores.json if it exists (else []), append 95, save it back. Three to four lines.
Q14. What does this print?
class A:
def greet(self):
return "Hello from A"
class B(A):
def greet(self):
return "Hello from B"
x = B()
print(x.greet())Section 6: Power Tools (Modules 10โ11)
Q15. One comprehension each:
a) Squares of odd numbers from 1 to 10
b) From names, a dict mapping each name to its length
Solutions
Q1. Guido van Rossum, 1989โ1991 โ named after Monty Python's Flying Circus, not the snake.
Q2. score (identifier), = (operator), score (identifier), + (operator), 10 (literal).
Q3. _temp โ
, Class2 โ
ยท my-score โ (hyphen), class โ (keyword), 7up โ (starts with digit).
Q4.
False 20 55555Wait โ y * 2 is 5 * 2 = 10. Correct output: False 20 10. (The trap: "5" == 5 is False โ different types.)
Q5. 2 3 8 โ remainder, floor division, exponent.
Q6.
a) "py" in word.lower()
b) 1 <= x <= 100Q7. print(data["b"][0]) โ dict key, then list index.
Q8. list(set([1, 3, 1, 2, 3, 1])) โ set removes duplicates (order not guaranteed; sort if needed).
Q9.
def fizzbuzz(n):
if n % 15 == 0:
return "FizzBuzz"
if n % 3 == 0:
return "Fizz"
if n % 5 == 0:
return "Buzz"
return str(n)Q10. print โ return:
def double(x):
return x * 2Q11. [1, 2, 99] โ lists are mutable and passed by reference; the function modified the original. (Contrast with numbers/strings, which are copied by value.)
Q12.
try:
n = int(input("Number: "))
except ValueError:
print("That's not a number")Q13.
import json, os
scores = json.load(open("scores.json")) if os.path.exists("scores.json") else []
scores.append(95)
json.dump(scores, open("scores.json", "w"), indent=2)Q14. Hello from B โ B overrides A's method; Python uses the child's version.
Q15.
a) [n ** 2 for n in range(1, 11) if n % 2 == 1]
b) {name: len(name) for name in names}๐ Scoring yourself
Either way: seventy lessons ago, "what is Python" was a genuine question. Look at you now. ๐