0
0
Pythonprogramming~20 mins

Nested conditional execution in Python - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Nested Conditional Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of nested if-else with numbers
What is the output of this Python code?
Python
x = 10
if x > 5:
    if x < 15:
        print("A")
    else:
        print("B")
else:
    print("C")
AB
BA
CC
DNo output
Attempts:
2 left
💡 Hint
Check the first condition, then the nested one inside it.
Predict Output
intermediate
2:00remaining
Nested if-else with strings
What will this code print?
Python
word = "hello"
if len(word) > 3:
    if word[0] == 'h':
        print("Starts with h")
    else:
        print("Long word")
else:
    print("Short word")
ALong word
BShort word
CError
DStarts with h
Attempts:
2 left
💡 Hint
Check the length and first letter of the word.
Predict Output
advanced
2:00remaining
Nested if-else with multiple conditions
What is the output of this code?
Python
num = 7
if num % 2 == 0:
    if num > 10:
        print("Even and large")
    else:
        print("Even and small")
else:
    if num > 5:
        print("Odd and large")
    else:
        print("Odd and small")
AOdd and large
BOdd and small
CEven and large
DEven and small
Attempts:
2 left
💡 Hint
Check if the number is even or odd, then check its size.
Predict Output
advanced
2:00remaining
Nested if-else with boolean logic
What will this code print?
Python
flag1 = True
flag2 = False
if flag1:
    if flag2:
        print("Both True")
    else:
        print("Only flag1 True")
else:
    print("flag1 is False")
Aflag1 is False
BBoth True
COnly flag1 True
DNo output
Attempts:
2 left
💡 Hint
Check the values of flag1 and flag2 carefully.
Predict Output
expert
2:00remaining
Nested if-else with variable reassignment
What is the value of variable result after running this code?
Python
x = 3
if x > 0:
    if x % 2 == 0:
        result = "Positive even"
    else:
        result = "Positive odd"
else:
    if x == 0:
        result = "Zero"
    else:
        result = "Negative"
A"Positive odd"
B"Negative"
C"Zero"
D"Positive even"
Attempts:
2 left
💡 Hint
Check if x is positive and then if it is even or odd.