Skip to content

This textbook is in beta – content is actively being refined. Report issues or suggestions

04.01 Control Structures In Python - Quiz

Check your understanding

  1. What are the three fundamental control structures in programming?

    • Input, Processing, Output
    • Variables, Functions, Classes
    • Sequence, Selection, Iteration { data-correct }
    • If, While, For
  2. In Python, which statement is used to make decisions based on conditions?

    • for
    • while
    • if { data-correct }
    • def
  3. What will this code print?

    for i in range(3):
        print(i)
    
    • 1, 2, 3
    • 0, 1, 2 { data-correct }
    • 3, 2, 1
    • 1, 2, 3, 4
  4. Which Python keyword is used to create an alternative condition in an if statement?

    • else if
    • elif { data-correct }
    • elseif
    • otherwise
  5. What type of loop should you use when you know exactly how many times you want to repeat something?

    • while loop
    • for loop { data-correct }
    • do-while loop
    • repeat loop
  6. What will happen with this code?

    count = 1
    while count <= 3:
        print(count)
    
    • Prints 1, 2, 3 and stops
    • Prints nothing
    • Creates an infinite loop { data-correct }
    • Causes a syntax error
  7. In the range range(2, 8, 2), what numbers will be generated?function

    • 2, 4, 6 { data-correct }
    • 2, 4, 6, 8
    • 0, 2, 4, 6, 8
    • 2, 3, 4, 5, 6, 7
  8. Which logical operator would you use to check if BOTH conditions are true?

    • or
    • and { data-correct }
    • not
    • xor
  9. What is the correct way to structure a nested if statement in Python?

    • Use curly braces {} to group code blocks
    • Use proper indentation to show which code belongs to each if { data-correct }
    • Use semicolons to separate conditions
    • Use parentheses around the entire block
  10. In a while loop, when does the loop stop executing?

    • When the condition becomes true
    • When the condition becomes false { data-correct }
    • After exactly 10 iterations
    • When a break statement is encountered
  11. Which control structure is being used in this pseudocode?

    IF score >= 90 THEN
        grade = "A"
    ELIF score >= 80 THEN
        grade = "B"
    ELSE
        grade = "C"
    
    • Sequence
    • Selection { data-correct }
    • Iteration
    • Function
  12. What is a common mistake that causes “off-by-one” errors in for loops?

    • Using the wrong variable name
    • Incorrect range boundaries { data-correct }
    • Missing indentation
    • Using while instead of for