04.01 Control Structures In Python - Quiz¶
Check your understanding
-
What are the three fundamental control structures in programming?
- Input, Processing, Output
- Variables, Functions, Classes
- Sequence, Selection, Iteration { data-correct }
- If, While, For
-
In Python, which statement is used to make decisions based on conditions?
forwhileif{ data-correct }def
-
What will this code print?
- 1, 2, 3
- 0, 1, 2 { data-correct }
- 3, 2, 1
- 1, 2, 3, 4
-
Which Python keyword is used to create an alternative condition in an if statement?
else ifelif{ data-correct }elseifotherwise
-
What type of loop should you use when you know exactly how many times you want to repeat something?
whileloopforloop { data-correct }do-whilelooprepeatloop
-
What will happen with this code?
- Prints 1, 2, 3 and stops
- Prints nothing
- Creates an infinite loop { data-correct }
- Causes a syntax error
-
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
-
Which logical operator would you use to check if BOTH conditions are true?
orand{ data-correct }notxor
-
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
-
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
-
Which control structure is being used in this pseudocode?
- Sequence
- Selection { data-correct }
- Iteration
- Function
-
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