Quizz

The full text of this chapter, to read or revisit. To practise, do the exercises.

▶ Do the exercises

Exercise 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")
Options
• "Condition A"
• "Condition B"
• "Condition C"
• Nothing

Hint : Evaluate the complex condition step by step.

Exercise 3 — Boolean Operators Results

Match each boolean expression with its result.

Items to match
• True and False
• not True
• False or True
• not False
Definitions
• False
• False
• True
• True

Exercise 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")
Options
• "Case 1"
• "Case 2"
• Nothing
• Error

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")
Options
• "Third"
• "Second"
• "First"
• Nothing

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")
Options
• "Good"
• "Normal"
• "Weak"
• Nothing

Hint : Follow the code execution and remember it stops at first True condition.

Exercise 10 — Comparison Operators

Match each comparison with its meaning.

Items to match
• ==
• !=
• >=
• <=
Definitions
• Equal to
• Not equal to
• Greater than or equal
• Less than or equal

Exercise 11 — Condition Keywords

Match each condition keyword with its purpose.

Items to match
• if
• elif
• else
• and
Definitions
• First condition to check
• Additional condition to check
• Runs when all conditions are false
• Both conditions must be true

Exercise 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")
Options
• armor is not defined
• Wrong indentation
• Missing else statement
• Too many elif statements

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")
Options
• "B"
• "A"
• "C"
• Nothing

Hint : Evaluate conditions inside parentheses first.

Exercise 15 — Complex Boolean Expressions

Match each complex expression with its result when a=True, b=False.

Items to match
• a and b
• a or b
• not a and b
• not (a and b)
Definitions
• False
• True
• False
• True

Exercise 16 — Condition Flow Results

Match each condition structure with what happens.

Items to match
• if ... elif ... else
• if ... if ... if
• if nested inside if
• if condition:
Definitions
• Only one block executes
• Multiple blocks can execute
• Checks multiple levels of conditions
• Executes only if True

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")
Options
• "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.

Items to match
• True or False and False
• not True and False
• (True or False) and False
• not (True and False)
Definitions
• True
• False
• False
• True

Exercise 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")
Options
• "Second"
• "First"
• "Third"
• Nothing

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")
Options
• "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")
Options
• "Second"
• "First"
• "Third"
• Nothing

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!")
Options
• Code 1
• Code 2
• Both are equally good
• Neither is good

Hint : Think about unnecessary comparisons with True.

Back to the course