Year 8 · Quiz 1

While loops

10 multiple-choice questions on while, updating the loop variable, sentinel values, and avoiding infinite loops. Matches Part 1 of the Year 8 Python tutorial.

Predict output Fill blanks Find errors
Fill in the blank

Question 1

A while loop repeats as long as a condition is ___.

Choose one answer
Predict the output

Question 2

What is printed?

n = 3
while n > 0:
    print(n)
    n = n - 1
print("Go")
Choose one answer
Find the error

Question 3

What is wrong with this code?

x = 1
while x < 5:
    print(x)
Choose one answer
Fill in the blank

Question 4

A while line must end with a ___.

Choose one answer
While vs for

Question 5

Which situation is a better fit for a while loop?

Choose one answer
Predict the output

Question 6

What does this print?

password = "hi"
while password != "python":
    print("Try again")
    password = "python"
print("Access granted")
Choose one answer
Sentinel values

Question 7

In a sentinel loop that stops on -1, why ask for input before the loop and again at the end?

Choose one answer
Find the error

Question 8

Which line is wrong?

mark = int(input("Mark: "))
while mark = -1:
    print(mark)
Choose one answer
Predict the output

Question 9

How many times is Hi printed?

count = 0
while count < 4:
    print("Hi")
    count = count + 1
Choose one answer
Fill in the blank

Question 10

To keep reading numbers until the user enters 0:

number = int(input("Enter a number: "))
while number ___ 0:
Choose one answer

Back to Year 8 Python · Next: Quiz 2