Courses/Python Mastery/Module 12: Capstone
Module 12 ยท Lesson 21-2 hoursBeginner๐Ÿงช Practice Session

๐Ÿงช Final Challenge

Lesson goal
A timed challenge covering all 12 modules โ€” 15 questions, from tokens to OOP.

๐Ÿงช 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?

code
x = "5"
y = 5
print(x == y, x + "!", y * 2)

Q5. What does this print?

code
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:

code
def double(x):
    print(x * 2)

result = double(15)

Q11. What does this print?

code
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?

code
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.

code
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.

code
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.

code
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:

code
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.

code
try:
    n = int(input("Number: "))
except ValueError:
    print("That's not a number")

Q13.

code
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.

code
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. ๐Ÿ