Chapter 4: Control Flow - Python
Chapter 4: Control Flow
Fill in the Blanks
1. The if statement in Python is used for ________.
Answer: decision-making
2. The ________ statement executes a block of code when the condition in the if statement is false.
Answer: else
3. The elif statement allows checking of ________ conditions.
Answer: multiple
4. A for loop iterates over a ________.
Answer: sequence
5. The while loop executes as long as the ________ remains true.
Answer: condition
6. An else block in a loop executes when the loop is ________.
Answer: exhausted
7. A loop can be exited early using the ________ statement.
Answer: break
True or False
1. The if statement is used for looping.
Answer: False
2. The else statement is optional in a control flow structure.
Answer: True
3. A for loop can only iterate over lists.
Answer: False
4. The break statement is used to terminate the loop immediately.
Answer: True
5. A while loop is always executed at least once.
Answer: False
6. The continue statement skips the rest of the code in the current iteration.
Answer: True
7. The elif statement can only follow an if statement.
Answer: True
Match the Following
Statement | Explanation |
---|---|
if statement | a) Decision-making |
else statement | b) Execute when condition is false |
for loop | c) Iterate over a sequence |
while loop | d) Execute based on condition |
break statement | e) Exit a loop early |
Answer: 1 → a, 2 → b, 3 → c, 4 → d, 5 → e
Answer in One Sentence
1. What is the purpose of an if statement?
Answer: It is used to execute code only when a specific condition is true.
2. What does the break statement do in a loop?
Answer: It terminates the loop immediately, skipping any remaining iterations.
3. What is the function of an else block in a loop?
Answer: It executes code when the loop finishes without encountering a break.
4. What does the continue statement do?
Answer: It skips the current iteration and continues with the next iteration.
5. What is an infinite loop?
Answer: A loop that continues to run indefinitely due to an unsatisfied exit condition.
Comments
Post a Comment