Python · Boolean in Depth
Quizz
The full text of this chapter, to read or revisit. To practise, do the exercises.
▶ Do the exercises
Exercise 1 — AND Basics
How many values need to be
True
for
and
to return
True
?
Options
• All of them
• At least one
• Exactly one
• None of them
Hint : AND requires ALL conditions to be True to return True.
Exercise 2 — OR Basics
What does
False or False or False
return?
Options
• ```False```
• ```True```
• ```Error```
• ```None```
Hint : OR returns False only when ALL values are False.
Exercise 3 — NOT Effect
What is the result of
not not not True
?
Options
• ```False```
• ```True```
• ```Error```
• ```None```
Hint : NOT returns the opposite of a boolean value. Double NOT brings you back to the original value.
Exercise 4 — Equality Check
What does
5 == 5
return?
Options
• ```True```
• ```False```
• ```5```
• ```Error```
Hint : The == operator checks if two values are equal and returns a boolean.
Exercise 5 — Operator Symbols
Match each operator with its meaning:
Items to match
• ==
• !=
• >=
• <=
Definitions
• Equal to
• Not equal to
• Greater than or equal to
• Less than or equal to
Exercise 6 — Basic Comparison
Complete the comparison to check if your Codémon's level is exactly 50:
codemon_level = 50 is_max = codemon_level ____ 50 print(is_max)
Options: == != > < >= <=
Hint : ```==``` is used to check if two values are exactly equal. ```!=``` checks if they are not equal.
Exercise 7 — Combined Expression
What is the result of
True or False and False
?
Options
• ```True```
• ```False```
• ```Error```
• ```None```
Hint : AND has higher priority than OR. Take care of it first, then the OR.
Exercise 8 — Inequality Check
What does
10 != 20
return?
Options
• ```True```
• ```False```
• ```10```
• ```Error```
Hint : ```==``` is used to check if two values are exactly equal. ```!=``` checks if they are not equal.
Exercise 9 — Battle Conditions
A Codémon can battle if its HP is more than zero. Complete:
hp = 50 can_battle = hp ____ 0 print(can_battle)
Options: == != > < >= <=
Hint : ```>``` checks if a value is greater than another. ```>=``` checks if it's greater than or equal.
Exercise 10 — Parentheses Priority
What is the result of
(True or False) and False
?
Options
• ```False```
• ```True```
• ```Error```
• ```None```
Hint : Parentheses are evaluated before AND, and AND before OR.
Exercise 11 — Comparison Results
Match each comparison with its result:
Items to match
• 7 < 10
• 15 > 20
• 8 >= 8
• 5 <= 3
Definitions
• True
• False
• True
• False
Exercise 12 — Arena Entry
You can enter the arena if your level is at least 15 AND you have at least 5 badges:
level = 20 badges = 6 can_enter = level ____ 15 ____ badges ____ 5 print(can_enter)
Options: >= <= > < == != and or >=
Hint : Use >= for 'at least' (includes the value), and AND when both conditions are required.
Exercise 13 — NOT with Comparison
What is the result of
not (5 > 10)
?
Options
• ```True```
• ```False```
• ```5```
• ```Error```
Hint : Evaluate what's in parentheses first, then apply NOT.
Exercise 14 — Complex AND
What is the result of
True and True and False and True
?
Options
• ```False```
• ```True```
• ```Error```
• ```None```
Hint : Compute it step by step. Remember with AND you need both sides to be True for it to be True.
Exercise 15 — Evolution Check
A Codémon evolves if its level is greater than 30 OR it has a special stone:
level = 25 has_stone = True can_evolve = level ____ 30 ____ has_stone print(can_evolve)
Options: > < >= <= == != and or
Hint : Greater than and greater than or equal to are different, pay attention!
Exercise 16 — Operator Behavior
Match each operator with when it returns
True
:
Items to match
• and
• or
• not
• ==
Definitions
• When ALL values are True
• When AT LEAST ONE value is True
• When the value is False
• When both values are equal
Exercise 17 — Range Check
What is the result of
10 <= 15 and 15 <= 20
?
Options
• ```True```
• ```False```
• ```15```
• ```Error```
Hint : Compute each comparison first, then apply AND.
Exercise 18 — Status Check
A Codémon can train if it's NOT poisoned AND NOT paralyzed:
is_poisoned = False is_paralyzed = False can_train = ____ is_poisoned ____ ____ is_paralyzed print(can_train)
Options: not not and or == !=
Hint : We need both sides to be True so he can train.
Exercise 19 — Mixed Operators
What is the result of
not (True and False)
?
Options
• ```True```
• ```False```
• ```Error```
• ```None```
Hint : Evaluate what's in the parentheses first, then apply NOT.
Exercise 20 — Expression Evaluation
Match each expression with its result:
Items to match
• not (False or False)
• True and not False
• False or True and False
• not True or not False
Definitions
• True
• True
• False
• True
Exercise 21 — Item Check
Check if you have more than 10 potions OR exactly 5 revives:
potions = 12 revives = 5 has_items = potions ____ 10 ____ revives ____ 5 print(has_items)
Options: > < >= <= == != and or
Hint : ```>``` is for strictly greater than, ```>=``` is for greater than or equal to
Exercise 22 — Complex OR
What is the result of
False or False or True or False
?
Options
• ```True```
• ```False```
• ```Error```
• ```None```
Hint : OR returns True if at least one value is True. Here, one value is True.
Exercise 23 — Tournament Entry
To enter, your level must be between 20 and 50 (inclusive) AND you must NOT be banned:
level = 35 is_banned = False can_enter = level ____ 20 ____ level ____ 50 ____ ____ is_banned print(can_enter)
Options: >= <= > < and and or not
Hint : This is a subtile combination of comparisons and boolean operators, take 2 minutes and you will get it!
Exercise 24 — Comparison Chain
What is the result of
5 != 5
?
Options
• ```False```
• ```True```
• ```5```
• ```Error```
Hint : The != operator checks if values are different.
Exercise 25 — Real Scenarios
Match each scenario with the correct expression:
Items to match
• Can fight if HP > 0 and not sleeping
• Need rest if tired or injured
• Level must be exactly 50
• Age must be 18 or more
Definitions
• hp > 0 and not sleeping
• tired or injured
• level == 50
• age >= 18
Back to the course