Hands-on Computer Science
My learning DE

Quiz10 min

Quiz: Loops

Eight questions on for and while loops, range(), accumulators, endless loops and enumerate().

Topics:Programming with Python

What does this program print?

for number in range(2, 10, 3):
    print(number)
  • 2, 5 and 8, each number on a line of its own
  • 2, 5, 8 and 11
  • 3, 6 and 9
  • 2, 3, 4, 5, 6, 7, 8 and 9

How often does for i in range(5): print("Hello") print the greeting?

  • Four times
  • Five times
  • Six times

What does this program print?

total = 0
for number in [4, 7, 1, 8]:
    if number > 3:
        total += number
print(total)
  • 20
  • 19
  • 3
  • 8

Someone wants to add up the prices and gets 3.5. Why?

for price in [2.5, 1.0, 3.5]:
    total = 0
    total += price
print(total)
  • print() is in the wrong place and should be indented.
  • total = 0 is in the body and resets the sum in every round.
  • += does not calculate reliably with decimal numbers.

What does this program print?

number = 100
rounds = 0
while number > 10:
    number = number // 2
    rounds += 1
print(rounds, number)
  • 4 6
  • 3 12
  • 4 6.25
  • 5 3

Which of these loops never stop if count is 0 beforehand? (several are right)

  • while count < 3: print(count)
  • while count < 3: count += 1
  • while count < 3: count -= 1
  • while count > 3: count += 1

For which tasks is while the right loop? (several are right)

  • Writing every item of a shopping list on a line of its own
  • Asking for the age until a number above 0 is entered
  • Printing the numbers from 1 to 10
  • Working out after how many years savings have doubled

What does this program print?

for number, item in enumerate(["milk", "bread"], start=1):
    print(number, item)
  • 0 milk and 1 bread
  • 1 milk and 2 bread
  • milk 1 and bread 2

Download with answers: CSV Anki

Back
More on this
Details
Level
Beginner
Modules
Digitization and Programming
In learning paths
Python for beginners
Code
8623
Updated
1 November 2026
Status
published

    A four-digit code takes you straight to the item.