Topic: Boolean Syntax
You are reviewing a pull request from a junior developer who is trying to set a flag for a user's subscription status. They have written the following code:
# Setting the subscription flag is_subscribed = true
When they try to run this script, Python throws a NameError: name 'true' is not defined. Based on Python's strict syntax rules, which of the following is the correct way to fix this?
Your Answer
Select the best option below.
Review your choice before proceeding.
Since Python treats True as the value 1 and False as the value 0 , you can use them in mathematical expressions.
Calculate the final result of the following expression:
(True+True+True)×False+Trueresult = (True + True + True) * False + True
Note: Use the calculator embedded in the quiz right panel if you need to verify your math!
Your Answer
Determine if the statement above is correct.
Pick the most accurate statement.
Since Python treats True as the value 1 and False as the value 0 , you can use them in mathematical expressions.
Calculate the final result of the following expression:
(True+True+True)×False+Trueresult = (True + True + True) * False + True
Note: Use the calculator embedded in the quiz right panel if you need to verify your math!
Your Answer
You are using the bool() function to check the "truthiness" of various data objects in a project. Which of the following values will resolve to True when passed into bool()? (Select all that apply)
Your Answer
Select all options that apply.
Ensure you have selected all applicable options.
When evaluating complex logical expressions, Python follows a specific order of operations for the keywords and, or, and not.
Arrange the following logical operators in the order they are executed by Python (from First to Last):
Your Answer
Reorder the list below.
You are building a feature that checks if a user has any notifications in their inbox. The variable inbox is currently an empty list: [].
inbox = [] has_mail = bool(inbox)
What is the value of has_mail?
Your Answer
Select the best option below.
Review your choice before proceeding.
Examine the table below comparing two variables:
| Variable | Value |
|---|---|
val_a | True |
val_b | "True" |
True or False: In Python, val_a and val_b are functionally identical and can be used interchangeably in logical operations without any conversion.
Your Answer
Determine if the statement above is correct.
Pick the most accurate statement.
Python's bool() function evaluates numerical values based on whether they are zero or non-zero.
What is the result of the following code? (Please provide the answer as True or False)
print(bool(0.000000001))
Your Answer
Which of the following values are considered Falsy in Python? (Select all that apply)
Your Answer
Select all options that apply.
Ensure you have selected all applicable options.
You are calculating a dynamic offset based on a series of boolean checks.
Arrange the following steps in the order Python would execute this calculation:
Expression: (True + 4) * False
- Multiply the result (5) by the value of False (0).
- Resolve True to the integer 1.
- Add 1 to 4 to get 5.
Your Answer
Reorder the list below.
You are writing a diagnostic script for a server. Each test returns a Boolean: True if it passes and False if it fails. You want to calculate a "Health Score" by treating these passes as numerical values.
Analyze the following diagnostic results:
score=(True+True+False+True)×25test_ram = True test_cpu = True test_disk = False test_network = True # Health Score Formula score = (test_ram + test_cpu + test_disk + test_network) * 25
What is the final integer value of the variable score?
Note: Use the calculator embedded in the quiz right panel if needed!
Your Answer
You are cleaning up a database and need to identify which data entries contain actual content versus which ones are "empty." Examine the table of variables below:
| Variable | Definition |
|---|---|
| a | [0] (A list containing the number zero) |
| b | "" (An empty string) |
| c | 0.0 (A float zero) |
| d | " " (A string with a single space) |
| e | None (The None object) |
Which of these variables will resolve to False when passed through the bool() function? (Select all that apply)
Your Answer
Select all options that apply.
Ensure you have selected all applicable options.
You are building a website that requires users to be at least 18 years old to enter. You use a comparison operator to generate a Boolean value based on the user's input.
user_age = 18 can_enter = user_age >= 18
True or False: In this scenario, the variable can_enter will hold the Boolean value True.
Your Answer
Determine if the statement above is correct.
Pick the most accurate statement.
Python uses "Short-Circuit Evaluation" for logical operators. For an and expression, if the first value is False, Python stops immediately because the whole expression can never be True.
Arrange the steps of how Python evaluates this line of code:
result = False and (10 / 0 == 0)
- Python assigns False to the variable result.
- Python evaluates the first operand and finds it is False.
- Python ignores the second operand (10 / 0 == 0), skipping the potential "Division by Zero" error.
Your Answer
Reorder the list below.
You are defining the access rules for a secure folder. A user is allowed in if they are an Admin OR if they have a Special Invite.
is_admin = False has_invite = True # Access logic access_granted = is_admin or has_invite
What is the resulting value of access_granted?
Your Answer
Select the best option below.
Review your choice before proceeding.
When fetching data from a database, a missing value is often represented in Python as None. To handle this safely, you check if the value exists by converting it to a Boolean.
What is the output of the following operation? (Please provide the answer as True or False)
data_value = None print(bool(data_value))
Your Answer
Booleans are flexible, but they have limits when interacting with other data types. Which of the following operations will result in a TypeError in Python? (Select all that apply)
Your Answer
Select all options that apply.
Ensure you have selected all applicable options.
The not operator is used to flip the Boolean value of an expression. It is often used to make code more readable (e.g., if not logged_in).
is_weekend = False # Logic: If it is NOT the weekend, set work_mode to True work_mode = not is_weekend
True or False: The value of work_mode in this code is True.
Your Answer
Determine if the statement above is correct.
Pick the most accurate statement.
Python evaluates logical expressions in a specific hierarchy.
Arrange the steps in the order Python would solve this expression:
result = not False or True and False
- Evaluate
not Falseto get True. - Evaluate
True and Falseto getFalse. - Evaluate
True or Falseto get the final result ofTrue.
Your Answer
Reorder the list below.
In Python, there is a technical difference between checking if two things have the same Value (==) versus if they are the exact same Object in memory (is).
Observe the following code:
x = (1 == 1) # This is True y = (2 == 2) # This is also True check_value = (x == y) check_identity = (x is y)
What are the values of check_value and check_identity?
Your Answer
Select the best option below.
Review your choice before proceeding.
You are developing an RPG game. A player can only unlock a "Special Ability" if they meet specific criteria. Look at the player's current stats below:
| Stat | Value | Requirement |
|---|---|---|
| level | 20 | Must be > 15 |
| has_key | True | Must be True |
| mana | 50 | Must be > 40 |
| is_cursed | False | Must be False |
Which of the following Python expressions will correctly evaluate to True, allowing the player to unlock the ability? (Select all that apply)
Your Answer
Select all options that apply.
Ensure you have selected all applicable options.
In Data Science, we often count how many items meet a condition by "summing" a list of Booleans. Since True is 1 and False is 0, the sum equals the count of True values.
Calculate the result of the following code:
final_score=(∑i=1nbooli)×10results = [True, False, True, True, False, True] # We multiply the total count of 'True' by 10 final_score = sum(results) * 10
Note: Use the calculator embedded in the quiz right panel if needed!
Your Answer
You are designing a security gateway. The logic follows a specific hierarchy of checks.
Arrange the steps in the order Python evaluates this nested expression:
access = (True or False) and not (False and True)
- Evaluate
(False and True)inside the second parentheses to getFalse. - Apply the
notto the result of the second parentheses to getTrue. - Evaluate
(True or False)inside the first parentheses to getTrue. - Perform the final
andoperation between the two results (True and True).
Your Answer
Reorder the list below.
In Python, True and False are Singletons. This means that no matter where they appear in your code, they always point to the exact same object in your computer's memory.
Examine this code:
a = (10 > 5) # Resolves to True b = (100 < 200) # Resolves to True # We check if they are the EXACT same object in memory identity_check = (a is b)
True or False: The variable identity_check will be True.
Your Answer
Determine if the statement above is correct.
Pick the most accurate statement.
Python allows a unique "shorthand" for checking if a number falls within a range.
x = 15 result = 10 < x < 20
How does Python technically evaluate this chained expression?
Your Answer
Select the best option below.
Review your choice before proceeding.
You are checking if a loop has any iterations to perform. You use the bool() function on a range object.
What is the output of the following code? (Provide the answer as True or False)
empty_range = range(0) print(bool(empty_range))
Your Answer
Python provides two powerful functions for checking lists of Booleans: any() and all().
Examine the following data:
test_results = [True, True, False, True]
Which of the following statements are correct regarding this data? (Select all that apply)
Your Answer
Select all options that apply.
Ensure you have selected all applicable options.
When math, comparisons, and logic are all in one line, Python follows a strict hierarchy.
Arrange these operators in the order they are executed (from First to Last):
- Logical Operators (
and,or) - Arithmetic Operators (
+,-) - Comparison Operators (
==,>)
Your Answer
Reorder the list below.
In a conditional statement, Python treats the None object as Falsy. However, this does not mean that None is equal to False.
Examine this code:
check_equality = (None == False) check_truthiness = bool(None) == bool(False)
True or False: The variable check_equality is False, but check_truthiness is True.
Your Answer
Determine if the statement above is correct.
Pick the most accurate statement.
Predict the final output of this advanced Boolean expression:
x = 10 y = 20 z = 0 result = (x < y or x / z == 0) and bool("Data")
Your Answer
Select the best option below.
Review your choice before proceeding.
Your Answer
Select the best option below.
Review your choice before proceeding.
Your Answer
Determine if the statement above is correct.
Pick the most accurate statement.
Your Answer
Your Answer
Select all options that apply.
Ensure you have selected all applicable options.
Your Answer
Reorder the list below.
Your Answer
Select the best option below.
Review your choice before proceeding.
Your Answer
Determine if the statement above is correct.
Pick the most accurate statement.
Your Answer
Your Answer
Select all options that apply.
Ensure you have selected all applicable options.
Your Answer
Reorder the list below.
Your Answer
Your Answer
Select all options that apply.
Ensure you have selected all applicable options.
Your Answer
Determine if the statement above is correct.
Pick the most accurate statement.
Your Answer
Reorder the list below.
Your Answer
Select the best option below.
Review your choice before proceeding.
Your Answer
Your Answer
Select all options that apply.
Ensure you have selected all applicable options.
Your Answer
Determine if the statement above is correct.
Pick the most accurate statement.
Your Answer
Reorder the list below.
Your Answer
Select the best option below.
Review your choice before proceeding.
Your Answer
Select all options that apply.
Ensure you have selected all applicable options.
Your Answer
Your Answer
Reorder the list below.
Your Answer
Determine if the statement above is correct.
Pick the most accurate statement.
Your Answer
Select the best option below.
Review your choice before proceeding.
Your Answer
Your Answer
Select all options that apply.
Ensure you have selected all applicable options.
Your Answer
Reorder the list below.
Your Answer
Determine if the statement above is correct.
Pick the most accurate statement.
Your Answer
Select the best option below.
Review your choice before proceeding.
