Recall & Review
beginner
What does an
if statement do in Python?It checks a condition and runs a block of code only if that condition is true.
Click to reveal answer
beginner
What is the purpose of the
else block?The
else block runs code when the if condition is false.Click to reveal answer
beginner
How does Python decide which block to run in an if–else structure?
Python checks the
if condition first. If true, it runs the if block. If false, it runs the else block.Click to reveal answer
beginner
What happens if the
if condition is true and there is an else block?Only the
if block runs. The else block is skipped.Click to reveal answer
beginner
Can you have an
if statement without an else?Yes. The
else block is optional. If missing, nothing happens when the if condition is false.Click to reveal answer
What will this code print?<br>
if 5 > 3:
print('Yes')
else:
print('No')✗ Incorrect
5 is greater than 3, so the if condition is true and 'Yes' is printed.
If the
if condition is false and there is no else, what happens?✗ Incorrect
If the condition is false and no else block exists, Python skips the if block and continues.
Which keyword starts the block that runs when the
if condition is false?✗ Incorrect
The
else keyword starts the block that runs when the if condition is false.What is the correct way to write an if–else statement in Python?
✗ Incorrect
Python uses colons and indentation to define blocks, as in option D.
What will this code print?<br>
if False:
print('A')
else:
print('B')✗ Incorrect
The condition is false, so the else block runs and prints 'B'.
Explain how Python decides which code to run in an if–else statement.
Think about the condition and the two possible paths.
You got /4 concepts.
Describe what happens if the if condition is false and there is no else block.
Consider what Python does when no alternative code is given.
You got /4 concepts.