Test: Python Basics

Quiz by topic · 15 questions · 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

  1. Read the program and first think on your own about what it will print.
  2. If you are not sure, type the program into Thonny (or another Python environment) and run it.
  3. Type the output into the box or choose one of the offered answers, then click “Check”. Each question can be checked only once.
  4. When you have answered every question, the result appears: percentage, grade, what you did well and what to review.
How to type the output: write exactly what the program prints. If there are several lines, put each line on a new line (Enter). Spaces at the start and end of a line do not count, but upper and lower case letters do: True is not the same as true.
Percentage0–49%50–64%65–79%80–89%90–100%
Grade12345

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:

Test (15 questions)

1. What does the program print?

print("Hello", "world", sep="-", end="!")
print("End")

2. What does the program print?

a = 17
b = 5
print(a / b, a // b, a % b)

3. What does the program print?

x = "4"
y = 3
print(x * y)
print(int(x) * y)

4. The user typed 14 and pressed Enter. What does the program print?

age = input()
print(age + "1")
print(int(age) + 1)

5. What does the program print?

price = 7.456
quantity = 3
print(f"Total: {price * quantity:.2f} dollars")

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")

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)

8. What does the program print?

total = 0
for i in range(1, 6):
    total = total + i
print(total)

9. What does the program print?

for i in range(10, 0, -3):
    print(i, end=" ")

10. What does the program print?

n = 1
steps = 0
while n < 50:
    n = n * 2
    steps += 1
print(n, steps)

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)

12. What does the program print?

fruit = ["apple", "pear", "plum", "peach"]
print(fruit[1])
print(fruit[-1])
print(fruit[1:3])

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))

14. What does the program print?

x = 10


def change():
    x = 99
    print("inside the function:", x)


change()
print("outside the function:", x)

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))

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.