Final exam
Python for Teens
Before you start
- 20 questions, drawn at random from a pool of 32.
- 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
What does print("Hi", "there", 5) display?
Question 2 of 20True or false
Score = 10 and score = 10 create the same variable in Python.
Question 3 of 20Match the pairs
Match each traceback ending to its likely cause.
Tap an answer, then tap the place where it belongs (or drag it there).
- NameError: name 'pritn' is not defined
- SyntaxError: unterminated string literal
- TypeError: can only concatenate str (not "int") to str
- IndexError: list index out of range
Question 4 of 20Sort into groups
Sort these values by data type.
Tap an item, then tap its group (or drag it there).
Question 5 of 20Work it out
What does this print?
``
x = 3
y = x
x = x + 4
print(x + y)
``
Question 6 of 20Choose one
Which line correctly stores the text Game Over in a variable?
Question 7 of 20Spot the mistake
Find the invalid variable names in this list of assignments.
Question 8 of 20Work it out
What is the value of 2 + 3 ** 2 * 2?
Question 9 of 20Match the pairs
Match each Python expression to the value it produces.
Tap an answer, then tap the place where it belongs (or drag it there).
- 23 // 4
- 23 % 4
- 8 / 4
- 3 * "ab"
Question 10 of 20Choose one
A program has minutes = 135. Which expression gives the number of full hours?
Question 11 of 20True or false
input() returns an integer when the user types only digits, such as 42.
Question 12 of 20Fill in the blanks
Fill in the blanks
word = "keyboard". Fill in the results: word[0] is , word[-1] is , and len(word) is .
Question 13 of 20Choose one
Which line prints Lap time: 52.37 s when t = 52.3668?
Question 14 of 20What would you do?
What would you do?
A program does age = int(input("Age: ")). The user types 15.5 and the program crashes with a ValueError. What's the right explanation?
Question 15 of 20Choose one
What does this print when points = 70?
``
if points >= 90:
print("Gold")
elif points >= 60:
print("Silver")
elif points >= 30:
print("Bronze")
else:
print("None")
``
Question 16 of 20Sort into groups
Sort these conditions by their value when age = 16 and member = False.
Tap an item, then tap its group (or drag it there).
Question 17 of 20True or false
if color == "red" or "blue": is True only when color is "red" or "blue".
Question 18 of 20Work it out
How many numbers does range(5, 20, 5) produce?
Question 19 of 20Work it out
What does this print?
``
count = 0
for ch in "banana":
if ch == "a":
count += 1
print(count)
``
Question 20 of 20Choose one
Which situation is best handled with a while loop rather than a for loop?
Question 21 of 20Spot the mistake
This countdown should print 5, 4, 3, 2, 1. Tap the line that causes an infinite loop.
Question 22 of 20Select all that apply
Which of these could random.randint(10, 12) return? Select all that apply.
Select all that apply.
Question 23 of 20Put in order
Order the lines of a dice game loop that stops after rolling a 6.
Drag the items, or use the arrow buttons, to put them in order.
- import random
- print("Rolled", roll)
- break
- if roll == 6:
- roll = random.randint(1, 6)
- while True:
Question 24 of 20Choose one
bag = ["apple", "rope", "torch"]. What does bag[len(bag) - 1] give?
Question 25 of 20Work it out
How many items are in nums after this code runs?
``
nums = [5, 8]
nums.append(1)
nums.pop()
nums.append(9)
nums.append(2)
``
Question 26 of 20Fill in the blanks
Fill in the blanks
letters = ["a", "b", "c", "d", "e", "f"]. The slice letters[2:5] contains items, and its first item is .
Question 27 of 20True or false
sum(scores) / len(scores) calculates the average of a list of numbers called scores.
Question 28 of 20Choose one
What is the value of result?
``
def triple(n):
print(n * 3)
result = triple(4)
``
Question 29 of 20Work it out
What does this print?
``
def combo(a, b=2):
return a * 10 + b
print(combo(3) + combo(1, 5))
``
Question 30 of 20Match the pairs
Match each idea about functions to its description.
Tap an answer, then tap the place where it belongs (or drag it there).
- Parameter
- Argument
- return
- Local variable
Question 31 of 20What would you do?
What would you do?
A quiz compares answers with if reply == "Paris":. Players who type paris or Paris (with a trailing space) are marked wrong. What's the best fix?
Question 32 of 20Put in order
Order the steps of a good debugging routine.
Drag the items, or use the arrow buttons, to put them in order.
- Change one thing and run the program again
- Read the last line of the error message
- Find an input that reproduces the bug
- Add print statements to inspect values