NEW
Font size
WorksheetsU6/L3 HS Kira- Nested If Statements
Total questions: 16
Worksheet time: 8mins
Which phrase best defines a nested if statement in programming?
An if statement that repeats until a condition is false
A conditional placed inside another if statement to make more complex decisions
A standalone if followed by multiple else statements
A loop that contains a conditional check
What is the primary purpose of a flowchart when planning conditionals?
To measure program speed in real time
To show the sequence of steps and decisions needed to solve a problem
To translate code directly into machine language
To store variables and their data types
In programming, conditionals allow the computer to do what?
Repeat code a fixed number of times
Make decisions based on whether something is true or false
Convert text to numbers automatically
Draw user interface elements by default
In a nested if structure, when does the inner if run?
Only if the outer if statement is true
Only if the outer if statement is false
Regardless of the outer condition
Only after an else clause executes
Complete the idea: The deeper the nesting, the more ____ the logic becomes.
efficient
confusing or complex
portable
deterministic
A nested if statement provides more control and flexibility by allowing a program to respond to ____ conditions.
static
multiple or layered
numeric-only
random
Consider the scenario: “If it’s raining, then check if I have an umbrella. If I do, I’ll go outside.” What makes this a nested decision?
It checks two unrelated conditions at the same time
It checks a second condition only after confirming the first is true
It always executes both checks regardless of weather
It uses loops to repeat the decision
In Python, what must be used carefully to show which code blocks belong to which conditions when nesting ifs?
Curly braces
Semicolons
Indentation
Line numbers
Why might writing a short story using nested conditionals be useful for students?
It helps memorize syntax without understanding logic
It demonstrates how decisions unfold step by step
It eliminates the need for testing code
It automatically generates flowcharts
Before coding a nested if statement, creating what can help plan the logic clearly?
A database schema
A flowchart
A variable table
A performance profile
Which Python keywords can be combined with nested ifs to handle different outcomes?
switch and case
else and elif
for and while
try and except
What is a potential downside of overusing nested if statements?
They always slow down the CPU
They make code harder to read and debug
They prevent the use of variables
They cannot include else clauses
Given age = 16 and money = 20, which nested condition correctly prints “You can have a ticket.” only when the person is old enough for PG-13 (age >= 13) and has more than $15?
if age > 13: if money >= 15: print("You can have a ticket.")
if age >= 13: if money > 15: print("You can have a ticket.")
if age >= 18: if money > 15: print("You can have a ticket.")
if money > 15: if age > 18: print("You can have a ticket.")
What is one advantage of using a nested if structure instead of multiple separate if statements when solving a problem?
Nested ifs always execute faster
Nested ifs allow checking a second condition only when the first is true, keeping logic orderly
Nested ifs reduce the number of variables required
Nested ifs remove the need for else or elif
In a game where a door opens only if the player chooses the left path and has a key, which structure best models this logic?
Two independent if statements checked in any order
A nested if where the key is checked only after confirming the left path
A while loop that runs until a key is found
A switch-case selecting the path
What strategy can help make complex nested-if code easier to understand and maintain?
Increase nesting depth to capture all cases in one place
Remove indentation to simplify the look
Use flowcharts and consider else/elif to reduce deep nesting
Replace all conditionals with loops
