Syntax
Comparison Operators
Logical Operators
If Structures
What prints?
100

What symbol MUST go at the end of an if header line?

A colon (:)

100

Which operator tests if two values are exactly equal?

==

100

Which keyword requires both conditions to be True?

and

100

Which keyword handles alternative conditions if the initial if is False?

elif

100

x = 10
if x > 15:    

     print("A")
else:    

     print("B")

"B"

200

How does Python know which statements belong inside an if block versus outside it?

Indentation (the indented block of code under the header)

200

What does the != operator check for?

"Not equal to"

200

Which keyword requires at least one condition to be True?

or

200

Which keyword acts as the catch-all fallback when no previous conditions match?

else

200

x = 8

if x > 5:

    print("Alpha")

if x > 2:

    print("Beta")

Both "Alpha" and "Beta" (on separate lines because these are two separate if statements).

300

What type of data (int, str, or bool) does an if statement evaluate to decide whether to run its block?

Boolean (True or False)

300

What does 10 >= 10 evaluate to? (True or False)

True

300

What does not True evaluate to?

False

300

How many elif blocks can you have under a single if statement?

As many as you want!

300

temp = 75

is_sunny = True


if temp > 80 or is_sunny:

    if temp < 70:

        print("Jacket")

    else:

        print("T-Shirt")

else:

    print("Sweater")

"T-Shirt" (Outer if evaluates to True because is_sunny is True. Inner if fails, running the inner else).

400

What happens if an if condition evaluates to False and there are no elif or else blocks attached to it?

Python simply skips the entire block and moves on to the next unindented line of code.

400

If a = 5 and b = "5", what does a == b evaluate to in Python and why?

False because Python compares both value and data type (int vs str).

400

Evaluate this expression: (5 > 2 or 10 < 2) and not (3 == 3)

False (Left side is True, but not (True) makes the right side False; True and False = False).

400

What is the structural difference between running three separate if statements versus an if-elif-elif chain?

Separate if statements check every condition independently. An if-elif-elif chain stops as soon as it finds the first True condition.

400

val = 20

if val > 10:

    val = val + 5

if val > 20:

    val = val * 2

else:

    val = val - 5

print(val)

50 (First if runs, updating val to 25. Then second if tests 25 > 20, which is True, making val equal 50).

500

Can you write an elif or else statement by itself without a preceding if statement? Why or why not?

No, elif and else depend on a parent if statement to evaluate prior conditions.

500

Given x = 10, rewrite x > 5 and x <= 15 as a chained comparison expression in Python syntax.

5 < x <= 15 (or 15 >= x > 5)

500

Given has_ticket = True and is_banned = False, does this evaluate to True or False?

has_ticket and not is_banned

True (not False becomes True, making it True and True).

500

How can a logic bug occur if you order your elif conditions from broadest to narrowest (e.g., checking x > 0 before x > 100)?

The broader condition (x > 0) triggers first for large numbers like 150, so the narrower check (x > 100) will never be reached.

500

a = True

b = False

if a or b:

    if not b and a:

        print("Option 1")

    else:

        print("Option 2")

else:

    print("Option 3")

"Option 1"