# simple ifx = 10if x > 5: print("x is greater than 5")#ans: x is greater than 5
# if with elseage = 18if age >= 18: print("Adult")else: print("Minor")#ans: Adult
# multiple conditionsscore = 85if score >= 90: print("A")elif score >= 80: print("B")elif score >= 70: print("C")else: print("F")#ans: B
# if inside ifx = 15if x > 10: if x < 20: print("Between 10 and 20")#ans: Between 10 and 20
# many elif branchesnum = 3if num == 1: print("One")elif num == 2: print("Two")elif num == 3: print("Three")#ans: Three
# what is printed?x = 5if x > 10: print("Big")else: print("Small")#ans: Small
# what about this?score = 90if score >= 90: print("A")elif score >= 80: print("B")#ans: A (only first matching condition)
# edge case?x = 0if x: print("True")else: print("False")#ans: False (0 is falsy)
# what prints?age = 18if age >= 18: print("Adult")if age < 21: print("Not 21 yet")#ans: Adult#ans: Not 21 yet (two separate if statements)
# tricky: what happens?if True: x = 5else: x = 10y = 20#ans: x is 5, y is 20 (y assignment is outside if)
# what is result?x = 15if x > 10: if x < 20: result = "Between" else: result = "Big"#ans: result is "Between"
# what prints?score = 70if score >= 70: passelse: print("Fail")#ans: nothing (pass does nothing)
# condition evaluation?x = Noneif x: print("Yes")else: print("No")#ans: No (None is falsy)
# multiple conditions?x = 5if x > 0 and x < 10: print("In range")#ans: In range
# what happens?if False: print("A")elif True: print("B")elif True: print("C")#ans: B (stops at first True)
# empty list check?items = []if items: print("Has items")else: print("Empty")#ans: Empty (empty list is falsy)
Google tag (gtag.js)