x = 10 if x > 5: if x > 15: print("A") else: print("B") else: print("C")
The variable x is 10, which is greater than 5, so the outer if is true.
Then the inner if checks if x is greater than 15, which is false.
So the else of the inner block runs, printing "B".
score = 75 if score >= 90: print("Excellent") elif score >= 70: print("Good") else: print("Try again")
The score is 75.
The first condition score >= 90 is false.
The second condition score >= 70 is true, so it prints "Good".
if (n := 4) > 3: print(f"Number {n} is greater than 3") else: print(f"Number {n} is not greater than 3")
The walrus operator n := 4 assigns 4 to n and returns 4.
Since 4 > 3 is true, it prints "Number 4 is greater than 3".
value = 2 match value: case 1: print("One") case 2: print("Two") case _: print("Other")
The variable value is 2.
The case 2 matches, so it prints "Two".
a = 5 b = 10 if a > 0 and b < 5: print("X") elif a > 0 or b < 5: print("Y") else: print("Z")
a is 5 (greater than 0), b is 10 (not less than 5).
The first condition a > 0 and b < 5 is false because b < 5 is false.
The second condition a > 0 or b < 5 is true because a > 0 is true.
So it prints "Y".
