Test: Python Basics
This test covers the whole area of Python basics: output, variables and types, arithmetic, input, text formatting, branching, loops, lists, functions and modules. Almost every question is “what does this program print?”.
How the test works
- Read the program and first think on your own about what it will print.
- If you are not sure, type the program into Thonny (or another Python environment) and run it.
- Type the output into the box or choose one of the offered answers, then click “Check”. Each question can be checked only once.
- When you have answered every question, the result appears: percentage, grade, what you did well and what to review.
True is not the same as true.| Percentage | 0–49% | 50–64% | 65–79% | 80–89% | 90–100% |
|---|---|---|---|---|---|
| Grade | 1 | 2 | 3 | 4 | 5 |
Each question is worth 1 point. Grades follow the Serbian school scale (1 = fail, 5 = excellent). The scale is a suggestion for self-assessment; a teacher can adjust it.
What the test covers
The topics of the test and the lessons where each topic is taught:
- Output (print) – First program in Python
- Variables, types and arithmetic – Variables and data types, Arithmetic operations
- Input and text formatting – Reading data (input), Formatting text
- Branching and logical operators – Branching: if, elif, else, Logical operators
- for and while loops – for and while loops, Iterations and basic algorithms
- Lists – Arrays and lists, Iterations and basic algorithms
- Functions and variable scope – Introduction to functions, Parameters and return values, Variable scope
- Modules and import – Modules and import
Test (15 questions)
1. What does the program print?
print("Hello", "world", sep="-", end="!")
print("End")
sep="-" puts a dash between the values instead of a space, and end="!" prints ! at the end instead of moving to a new line. That is why End stays on the same line.2. What does the program print?
a = 17
b = 5
print(a / b, a // b, a % b)
/ is ordinary division and always gives a decimal number (3.4), // is integer division (3) and % is the remainder (17 = 3·5 + 2).3. What does the program print?
x = "4"
y = 3
print(x * y)
print(int(x) * y)
x is text (str), so "4" * 3 repeats the text three times: 444. Only int(x) turns the text into a number, so 4 * 3 = 12.4. The user typed 14 and pressed Enter. What does the program print?
age = input()
print(age + "1")
print(int(age) + 1)
input() always returns text. "14" + "1" joins two texts into 141, and after int(age) the program computes 14 + 1 = 15.5. What does the program print?
price = 7.456
quantity = 3
print(f"Total: {price * quantity:.2f} dollars")
:.2f format in the f-string prints the number with two decimal places and rounds it: 22.37.6. What does the program print?
points = 74
if points >= 90:
print("excellent")
elif points >= 75:
print("very good")
elif points >= 60:
print("good")
else:
print("sufficient")
good is printed. After the first true condition, the remaining parts (elif, else) are skipped.7. What does the program print?
x = 8
print(x > 5 and x < 10)
print(x % 2 == 1 or x > 10)
print(not x == 8)
and: both conditions are true → True. or: 8 is even and not greater than 10, so neither condition is true → False. not turns the true x == 8 into False.8. What does the program print?
total = 0
for i in range(1, 6):
total = total + i
print(total)
range(1, 6) gives the numbers 1, 2, 3, 4 and 5 – without 6. The sum is 1 + 2 + 3 + 4 + 5 = 15. print is not indented, so it runs once, after the loop.9. What does the program print?
for i in range(10, 0, -3):
print(i, end=" ")
end=" ", all numbers are on the same line.10. What does the program print?
n = 1
steps = 0
while n < 50:
n = n * 2
steps += 1
print(n, steps)
n doubles: 2, 4, 8, 16, 32, 64 – that is 6 steps. When n = 64, the condition n < 50 is no longer true and the loop ends.11. What does the program print?
numbers = [4, 9, 2, 7, 5]
largest = numbers[0]
for num in numbers:
if num > largest:
largest = num
print(largest)
largest. The largest number in the list is 9.12. What does the program print?
fruit = ["apple", "pear", "plum", "peach"]
print(fruit[1])
print(fruit[-1])
print(fruit[1:3])
fruit[1] is the second element (pear). fruit[-1] is the last element. The slice fruit[1:3] takes the elements with indexes 1 and 2 – the limit 3 is not included.13. What does the program print? (The output has two lines – type each line on a new line.)
def area(a, b=2):
return a * b
print(area(5))
print(area(3, 4))
b has the default value 2. In the first call b is not given, so the result is 5 · 2 = 10. In the second call b = 4, so the result is 3 · 4 = 12.14. What does the program print?
x = 10
def change():
x = 99
print("inside the function:", x)
change()
print("outside the function:", x)
x = 99 inside the function creates a new, local variable. It exists only while the function runs; the global variable x stays 10.15. What does the program print? (The output has two lines – type each line on a new line.)
import math
print(math.sqrt(49))
print(math.floor(7.9), math.ceil(7.1))
math.sqrt always returns a decimal number, so the square root of 49 is 7.0 (not 7). floor rounds down (7) and ceil rounds up (8).After the test
The result above shows which topics to review and links to the right lessons. Review the lesson, do its examples, then take the test again.
- the whole course in order – Guide: Python Basics
- practice tasks – Mini tasks: loops, Mini tasks: temperature and quiz, Mini projects for beginners
- other quizzes – Guide: Quizzes by Topic
- written tests by topic – Guide: Test and Assessment Exercises
