Final exam
Python for Beginners
Before you start
- 20 questions, drawn at random from a pool of 36.
- Pass mark: 70%. Your final score is 30% practice + 70% exam.
- No time limit, but finish within 3 hours. You can move between questions before you submit.
- Failed? Review the lessons and try again: every attempt gets a new set of questions.
Question 1 of 20Choose one
Which line prints the text Hello, world! in Python 3?
Question 2 of 20True or false
In a script (not the interactive prompt), a line containing only the expression 2 + 2 displays 4.
Question 3 of 20Choose one
Which part of a traceback should you usually read first?
Question 4 of 20What would you do?
What would you do?
What does this program print?
x = 5
y = x
x = x + 3
print(x, y)Question 5 of 20Sort into groups
Sort each value by its Python type.
Tap an item, then tap its group (or drag it there).
Question 6 of 20Spot the mistake
Tap the two invalid variable names.
Question 7 of 20Work it out
What is the value of 23 // 4?
Question 8 of 20Work it out
What is the value of 23 % 4?
Question 9 of 20Choose one
What is the value of (2 + 4) * 3 ** 2?
Question 10 of 20Choose one
Why might total == 0.3 be False even though total was computed as 0.1 + 0.2?
Question 11 of 20Fill in the blanks
Fill in the blanks
For s = "notebook", s[0:4] is and s[-4:] is .
Question 12 of 20Choose one
With name = "Ana" and pts = 7.456, what does f"{name} scored {pts:.1f}" produce?
Question 13 of 20What would you do?
What would you do?
This script should store the email address in lowercase without spaces.
email = " Ana@Example.COM "
email.strip().lower()
print(email)What is printed, and why?
Question 14 of 20Choose one
Which expression turns "a;b;c" into the list ["a", "b", "c"]?
Question 15 of 20What would you do?
What would you do?
A user types 12 when this program runs.
hours = input("Hours worked: ")
pay = hours * 2
print(pay)What is printed?
Question 16 of 20True or false
int("3.5") returns 3.
Question 17 of 20Choose one
Which condition is True only when age is between 13 and 19 inclusive?
Question 18 of 20What would you do?
What would you do?
What does this program print for score = 75?
if score >= 60:
print("D")
elif score >= 70:
print("C")
else:
print("F")Question 19 of 20True or false
The condition day == "Sat" or "Sun" is True only on Saturdays and Sundays.
Question 20 of 20Select all that apply
Which values are truthy, meaning an if statement treats them as true? Select all that apply.
Select all that apply.
Question 21 of 20Work it out
How many times does the body of for i in range(0, 20, 4): run?
Question 22 of 20What would you do?
What would you do?
How many lines does this program print?
n = 10
while n > 0:
print(n)
n = n - 3Question 23 of 20Match the pairs
Match each loop keyword or pattern to its purpose.
Tap an answer, then tap the place where it belongs (or drag it there).
breakcontinueenumerate(items)zip(a, b)
Question 24 of 20What would you do?
What would you do?
What does this program print?
total = 0
for n in [4, 7, 1]:
total += n
print(total)Question 25 of 20Choose one
After nums = [5, 2, 9] and nums.append([1, 3]), what is len(nums)?
Question 26 of 20Choose one
Which line produces a new sorted list in ranked while leaving scores unchanged?
Question 27 of 20Fill in the blanks
Fill in the blanks
The comprehension [p * 2 for p in [3, 5, 8] if p > 4] produces [, ].
Question 28 of 20What would you do?
What would you do?
What does this program print?
stock = {"pens": 10, "pads": 4}
stock["pens"] = stock["pens"] - 3
stock["clips"] = 25
print(len(stock), stock["pens"])Question 29 of 20Sort into groups
Choose the best collection for each job.
Tap an item, then tap its group (or drag it there).
Question 30 of 20What would you do?
What would you do?
What does this program print?
def area(w, h=2):
return w * h
print(area(5) + area(3, 4))Question 31 of 20Choose one
What does a function return if it ends without reaching a return statement?
Question 32 of 20True or false
A parameter with a default value, such as def f(a, b=1), can be omitted when calling the function.
Question 33 of 20What would you do?
What would you do?
A program opens a log file with open("app.log", "a") and writes one line. The file already had 200 lines. What is true afterwards?
Question 34 of 20Choose one
Which except clause should handle a user typing "abc" when the program runs int(input())?
Question 35 of 20Select all that apply
Which of these are good practices with try and except? Select all that apply.
Select all that apply.
Question 36 of 20Work it out