- Structured Programming
- Selection Control Structures
- Code Blocks
- Condition Examples: Temperature Conversion Pseudocode
- Condition Examples: Python Code
- Structured Quiz 5 questions
- If and If-else Statement
- If and If-else Quiz 5 questions
- Chained Decisions
- Chained Decisions Quiz 5 questions
- Nested Decision
- Nested Decision Quiz 5 questions
- Conditional Expressions
- Conditional Expressions Quiz 5 questions
Quiz Question 1 of 5
Given the following nested if-else
structure, which modification could lead to logic errors when handling different game IDs and player counts?
if game == 1:
if players < 2:
print("Not enough players")
elif players > 4:
print("Too many players")
else:
print("Ready to start")
if game == 2:
if players < 3:
print("Not enough players")
elif players > 6:
print("Too many players")
else:
print("Ready to start")
Choose the correct answer below:
-
A
Removing the
elif
conditions and replacing them with additionalif
statements for each player count scenario. -
B
Adding an additional
else
block after the game ID checks to handle unexpected player counts. -
C
Consolidating the player count checks into a single block of code outside the game ID checks.
-
D
Combining both game ID checks into a single
if
statement with multiple conditions.