Python mock tests
Test yourself on the whole course, against the clock: questions from every module, then coding problems you solve and run right here. Your score comes at the end, with every answer explained.
Each mock test has 12 questions drawn from the lessons and up to 3 coding problems, and 45 minutes on the clock, which keeps running if you reload. Questions are worth a point each, and each coding problem 4 points, shared by its tests. Score 60% or more to pass; your best score is kept.
- 01Mock test 112 questions · 3 coding problems · 45 minutes · 24 points
- 02Mock test 212 questions · 3 coding problems · 45 minutes · 24 points
- 03Mock test 312 questions · 3 coding problems · 45 minutes · 24 points
Part A · 12 questions
- Which statement about lists is true?
- What happens if you print a variable that was only created inside a function, from outside it?
- What does sorted(words, key=len) do?
- Which line correctly calls a function named show_menu?
- What does enumerate(["a", "b"], start=1) produce when looped over?
- Which hint means "an int or None"?
- What does len("New York") return?
- For s = "coding", what is s[1:4]?
- How do you print a literal { in an f-string?
- What does JSON null become in Python?
- What does a bare raise inside an except block do?
- What is printed? def f(): return 1; print(2) then print(f())
Part B · 3 coding problems
Write each answer and run its tests as often as you like: everything is marked when you submit. Each problem is worth 4 points, shared by its tests.
- 1Read a date and timeMedium · 4 points
Read a date and time written as
day/month/year hours:minutes, and print it in ISO form.Input04/11/2026 14:30
Expected output2026-11-04T14:30:00
Loading the editor… - 2Two files at onceMedium · 4 points
Copy every line of
in.txtintoout.txtin capital letters, opening both files in onewithstatement. Then printout.txt.Expected outputONE TWO
Loading the editor… - 3Valid JSON?Medium · 4 points
Read a line. If it's valid JSON, print the type name of the Python value it becomes; otherwise print
Invalid JSON.Input[1, 2]
Expected outputlist
Loading the editor…
Part A · 12 questions
- What is a common use of a class method?
- What can a lambda body contain?
- What type does input() return?
- What is x after x = [3, 1, 2]; x = x.sort()?
- Which method makes "x" in obj work?
- How do you read a property called area on an object r?
- Given nums = [2, 3], what does pow(*nums) compute?
- What is -7 // 2?
- What is {{"a": 1}, {"a": 2}}?
- Which string is valid Python?
- What does from math import pi, sqrt let you write?
- What does 3 != 3 evaluate to?
Part B · 3 coding problems
Write each answer and run its tests as often as you like: everything is marked when you submit. Each problem is worth 4 points, shared by its tests.
- 1Flatten with yield fromHard · 4 points
Write a generator
flatten(items)that yields every number from a list whose items may be lists, nested to any depth, usingyield fromfor the sublists.Expected output[1, 2, 3, 4, 5] 60
Loading the editor… - 2Running totalsHard · 4 points
Read a line of whole numbers. Print the running total after each one, all on one line separated by spaces.
Input1 2 3 4
Expected output1 3 6 10
Loading the editor… - 3Gaps between neighboursHard · 4 points
Read a line of whole numbers and print a list of the differences between each number and the one after it, using
itertools.pairwise.Input1 4 9 16
Expected output[3, 5, 7]
Loading the editor…
Part A · 12 questions
- What does a @classmethod receive as its first argument?
- Which value has the type bool?
- What does print("5 + 5") show?
- What does the "as f" part of with open(...) as f do?
- How should you check whether x is None?
- Which expression is True?
- What does -> list[str] after a function's parameters mean?
- Which method lets sorted() order your objects?
- In a match statement, what does case _: do?
- What is the purpose of the base case in a recursive function?
- What is the relationship between a class and an object?
- Inside a method, how do you call another method of the same object?
Part B · 3 coding problems
Write each answer and run its tests as often as you like: everything is marked when you submit. Each problem is worth 4 points, shared by its tests.
- 1Endless even numbersMedium · 4 points
Write a generator
evens()that yields 0, 2, 4... forever. The checker takes the first five withislice.Expected output[0, 2, 4, 6, 8] 0 2 4
Loading the editor… - 2Many shapes, one callMedium · 4 points
Give
RectandCircleanarea()method each (use3.14for pi). The checker loops over a mixed list and callsarea()on every shape without checking its type.Expected outputRect 6 Circle 3.14 Rect 16 25.14
Loading the editor… - 3Look inside a moduleMedium · 4 points
Import the
stringmodule. Print a list of the names in it that start withascii(usedir()), then the first five capital letters fromstring.ascii_uppercase.Expected output['ascii_letters', 'ascii_lowercase', 'ascii_uppercase'] ABCDE
Loading the editor…