π§ͺ 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 55555
Wait β 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 <= 100
Q7. 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 * 2
Q11. [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
- 13β15 correct: You didnβt take a course β you became a Python programmer. The Streamlit course is your playground now.
- 9β12: Strong. Revisit the modules behind your misses β theyβre reference material now.
- 5β8: Solid foundation; redo the practice sessions of your two weakest modules before the capstone.
- Below 5: No shame β retake the modules in order. The course is free and forever.
Either way: seventy lessons ago, βwhat is Pythonβ was a genuine question. Look at you now. π