Quizz
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercisesExercise 1 — Nested Codémon Battle Check
Create a nested condition to check both the Codémon's shield and health.
Hint : Nested conditions means multiple if statements inside each other. Remember to keep the indentation correct.
Exercise 2 — Complex Boolean Evaluation
What will be printed?
x = 5
y = 10
if (x == y) or (x > 0 and y < 20):
print("Condition A")
elif x > y:
print("Condition B")
else:
print("Condition C")"Condition A""Condition B""Condition C"Hint : Evaluate the complex condition step by step.
Exercise 3 — Boolean Operators Results
Match each boolean expression with its result.
True and Falsenot TrueFalse or Truenot FalseFalseFalseTrueTrueExercise 4 — Codémon Attack Damage System
Complete the damage calculation system (100+ is critical, 50+ is high, 25+ is medium, rest is low).
Hint : Order conditions from highest to lowest.
Exercise 5 — Boolean Logic Evaluation
What will be printed?
a = True
b = False
c = True
if not (a and b) or c:
print("Case 1")
else:
print("Case 2")"Case 1""Case 2"Hint : Evaluate the boolean expression step by step.
Exercise 6 — Status Check
Complete the Codémon status check (check if Codémon is alive first, then check power level).
Hint : Use nested conditions for multiple checks.
Exercise 7 — Operator Precedence
What will this code print?
x,y,z = 11,10,15
if x < y and y < z or x == z:
print("First")
elif x < z and y > x:
print("Second")
else:
print("Third")"Third""Second""First"Hint : Remember the order: and is evaluated before or.
Exercise 8 — Boss Battle Condition
Complete the boss battle condition (trainer wins if Codémon has full health AND either a special attack OR magic power).
Hint : Group conditions with parentheses properly.
Exercise 9 — Elif Execution Flow
What will this code print?
codemon_power = 75
if codemon_power > 100:
print("Super")
elif codemon_power > 60:
print("Good")
elif codemon_power > 70:
print("Normal")
else:
print("Weak")"Good""Normal""Weak"Hint : Follow the code execution and remember it stops at first True condition.
Exercise 10 — Comparison Operators
Match each comparison with its meaning.
==!=>=<=Exercise 11 — Condition Keywords
Match each condition keyword with its purpose.
ifelifelseandExercise 12 — Code Error Detection
What's wrong with this code?
speed = 100
if speed >= 100 and armor >= 50:
print("Tank mode")
elif not speed < 50:
print("Fast mode")
elif speed > 75:
print("Normal mode")Hint : Check the logic of the conditions carefully.
Exercise 13 — Treasure Chest
Complete the treasure chest logic (check if chest is unlocked, then if trainer has enough space).
Hint : Think about the order of condition checks.
Exercise 14 — Parentheses Evaluation
What will this code print?
x, y, z = 10, 20, 15
if (x < y and y < z) or (x == z and y > x):
print("A")
elif x > z or y > z:
print("B")
else:
print("C")"B""A""C"Hint : Evaluate conditions inside parentheses first.
Exercise 15 — Complex Boolean Expressions
Match each complex expression with its result when a=True, b=False.
a and ba or bnot a and bnot (a and b)FalseTrueFalseTrueExercise 16 — Condition Flow Results
Match each condition structure with what happens.
if ... elif ... elseif ... if ... ifif nested inside ifif condition:Exercise 17 — Training Medal System
What will be printed ?
score = 85
if score >= 90:
print("Gold medal")
elif score >= 80:
print("Silver medal")
elif score >= 70:
print("Bronze medal")
else:
print("No medal")"Silver medal""Gold medal""Bronze medal""No medal"Hint : Follow the condition checks in order.
Exercise 18 — Operator Precedence Order
Match each expression with its evaluation result.
True or False and Falsenot True and False(True or False) and Falsenot (True and False)TrueFalseFalseTrueExercise 19 — Boolean Operator Precedence
What will be printed?
a, b, c = True, False, True
if not a or b and c:
print("First")
elif a and not b:
print("Second")
else:
print("Third")"Second""First""Third"Hint : Remember: and has higher precedence than or.
Exercise 20 — Secret Door Access
Complete the secret door condition (needs key AND correct password, OR admin access).
Hint : Think about grouping related conditions.
Exercise 21 — Nested Condition Path
What's the output?
power = 50
shield = 100
if power > 75:
if shield > 50:
print("Strong")
else:
print("Vulnerable")
elif power > 25:
if shield > 75:
print("Defensive")
else:
print("Balanced")"Defensive""Balanced""Strong""Vulnerable"Hint : Follow the code path carefully.
Exercise 22 — Trainer Rank System
Complete the trainer rank system (100+ is master, 50+ is expert, 20+ is advanced, rest is beginner).
Hint : Remember to check from highest to lowest.
Exercise 23 — Not Operator Evaluation
What is the output of this code?
a = True
b = False
if not a and b:
print("First")
elif not (a and b):
print("Second")
else:
print("Third")"Second""First""Third"Hint : Evaluate the not operations first.
Exercise 24 — Boss Fight Conditions
Complete the boss fight code (check if trainer is alive, then if they have enough power OR special ability).
Hint : Use nested conditions and combine with OR.
Exercise 25 — Clean Code Practices
Which code is clearer?
# Code 1
if has_key and has_map and has_codeball:
print("Ready!")# Code 2
if has_key == True and has_map == True and has_codeball == True:
print("Ready!")Hint : Think about unnecessary comparisons with True.