placeholder image to represent content

Python programming, For loops, while loops, If statements and variables

Quiz by Fred Barber

Our brand new solo games combine with your quiz, on the same screen

Correct quiz answers unlock more play!

New Quizalize solo game modes
9 questions
Show answers
  • Q1
    What is the output of the following Python code?x = 5while x > 0: print(x) x = x - 1
    12345
    54321
    11111
    55555
    54321
    30s
  • Q2
    What is the output of the following Python code snippet?for i in range(1, 6): if i % 2 == 0: print(i) else: continue
    24
    12345
    2
    135
    4
    24
    30s
  • Q3
    What is the purpose of the 'if' statement in Python?
    To conditionally execute code based on a given condition
    To define a named storage location for a value
    To iterate over a sequence of elements
    To repeat a block of code a specified number of times
    30s
  • Q4
    What is the output of the following Python code?x = 0while x < 10: print(x) x += 2
    02468
    02468
    13579
    012345678910
    1086420
    30s
  • Q5
    Which of the following is a correct Python variable name?
    variable-my
    myVariable
    1_variable
    Variable1
    my_variable
    30s
  • Q6
    What is the output of the following Python code?x = 10while x >= 0: print(x) x -= 1
    12345678910
    109876543210
    012345678910
    109876543210
    0102030405060708090100
    30s
  • Q7
    What is the output of the following Python code?x = 5for i in range(x): print(i)
    12345
    55555
    01234
    01234
    43210
    30s
  • Q8
    What is the correct syntax to check if a variable 'x' is equal to 10 in Python?
    if x != 10:
    if x == 10:
    if x =! 10:
    if x === 10:
    if x = 10:
    30s
  • Q9
    What is the purpose of a while loop in Python?
    To repeatedly execute a block of code as long as a condition is True
    To iterate over a sequence of elements
    To conditionally execute code based on a given condition
    To define a named storage location for a value
    30s

Teachers give this quiz to your class