Test your understanding of Python's decision-making power!
๐ฏ Multiple Choice Questions
1. What is a condition in Python programming?
A statement that can only be True or False
A type of variable
A function that prints text
A way to create loops
Correct! A condition is a statement that evaluates to either True or False, like asking a yes/no question that helps your program make decisions.
2. What happens if you forget to indent the code inside an if statement?
The code runs normally
Python gives an IndentationError
The code runs twice
Python ignores the if statement
Correct! Python requires proper indentation to know which lines belong to the if statement. Without it, you'll get an IndentationError.
3. What's the difference between = and == in Python?
There is no difference
= is for comparing, == is for assigning
= is for assigning, == is for comparing
Both are used for math operations
Correct! = assigns a value to a variable ("make this equal to that"), while == compares two values ("are these equal?").
4. What does the modulo operator (%) do?
Calculates percentages
Returns the remainder after division
Multiplies two numbers
Divides two numbers
Correct! The modulo operator (%) returns the remainder after division. For example, 13 % 5 = 3 because 13 รท 5 = 2 with remainder 3.
5. When does an else block execute?
Always, regardless of the if condition
Only when the if condition is True
Only when the if condition is False
Never, it's just for documentation
Correct! The else block only runs when the if condition is False. It's like having a backup plan that automatically kicks in.
๐ Code Analysis
6. What will this code output when temperature = 25?
temperature = 25
if temperature > 30:
print("It's hot!")
elif temperature > 20:
print("It's warm!")
else:
print("It's cool!")
It's hot!
It's warm!
It's cool!
Nothing will print
Correct! Since 25 > 20 is True, Python executes the first elif block and prints "It's warm!" Python stops checking conditions after finding the first True one.
7. What does this condition check?
if age >= 18 and has_license == True:
If age is 18 or has a license
If age is 18 and has a license
If age is at least 18 and has a license
If age is exactly 18 and has a license
Correct! The condition checks if age is at least 18 (>= means greater than or equal to) AND has_license is True. Both conditions must be true.
8. What will happen with this code?
number = 10
if number % 2 == 0:
print("Even")
else:
print("Odd")
Prints "Even"
Prints "Odd"
Prints both "Even" and "Odd"
Causes an error
Correct! 10 % 2 = 0, and 0 == 0 is True, so it prints "Even". This is a common way to check if a number is even (remainder 0 when divided by 2).
๐ง Logical Operators
9. Which logical operator means "both conditions must be True"?
or
and
not
if
Correct! The 'and' operator is "the perfectionist" - both conditions must be True for the entire expression to be True.
10. What does the 'not' operator do?
Checks if two things are different
Flips True to False and False to True
Combines two conditions
Creates a new variable
Correct! The 'not' operator is like "opposite day" - it flips the boolean value. not True becomes False, and not False becomes True.
11. When is this condition True?
if day == "Monday" or day == "Friday":
Only when day is "Monday"
Only when day is "Friday"
When day is either "Monday" or "Friday"
When day is both "Monday" and "Friday"
Correct! The 'or' operator is "the flexible friend" - it's True when at least one condition is True, so either Monday OR Friday will work.