Python Unit 6: Conditionals Practice Questions

Practice questions for Python Unit 6 on conditionals (if, elif, and else statements and boolean logic), with explanations for every answer.

150 questions · Python Programming · by Study Foxy

Study these questions free

Questions

  1. What does this program print? is_open = 9 < 5 print(is_open)

    • False
    • 9 < 5
    • is_open
    • True
  2. What does this program print? a = 10 b = a == 10 print(type(b))

    • <class 'bool'>
    • True
    • <class 'int'>
    • <class 'str'>
  3. has_key holds the text "False" in quotes. What does the program print? has_key = "False" if has_key: print("open") else: print("locked")

    • open
    • locked
    • Nothing is printed
    • TypeError
  4. What does this program print? ready = True print("Ready: " + ready)

    • TypeError
    • Ready:True
    • Ready: ready
    • Ready: True
  5. What does this program print? ready = True print(f"Ready: {ready}")

    • Ready: True
    • Ready: ready
    • Ready: {ready}
    • TypeError
  6. What happens when this runs? done = false print(done)

    • NameError
    • False
    • None
  7. is_big is set while x is 7, then x changes. What prints? x = 7 is_big = x > 5 x = 2 print(is_big)

    • True
    • 2
    • x > 5
    • False
  8. What does this program print? light = True light = not light light = not light light = not light print(light)

    • False
    • not light
    • NameError
    • True
  9. A program needs to remember whether a student turned in homework so it can use the value in an if statement later. Which line is the best choice?

    • turned_in = True
    • turned_in = "yes"
    • turned_in == True
  10. What does this program print? score = 72 passed = score >= 70 print(passed, not passed)

    • True False
    • 72 True
    • False True
    • True True
  11. Which program prints True?

    • x = 4 print(x % 2 == 0)
    • x = 4 print(x / 2 == 0)
    • x = 4 print("x % 2 == 0")
    • x = 5 print(x % 2 == 0)
  12. What does this program print? is_member = True print(str(is_member) + "!")

    • True!
    • TypeError
    • is_member!
    • 1!
  13. The user types True. What does the program print? answer = input("Done? ") print(answer == True)

    • Done? True False
    • Done? True True
    • TypeError
    • False
  14. A student writes needs_water = "True" (with quotes). Printing it looks the same as the Boolean. What is the real problem?

    • It is a string, so even "False" would count as true
    • Python cannot print a string that looks like a Boolean
    • It raises a NameError the moment the variable is printed
    • Nothing; quotes around True and False are optional
  15. What does this program print? wet = True print(wet == "True")

    • False
    • None
    • True
    • wet
  16. Which variable name best describes a Boolean that stores whether a game is over?

    • game_over
    • game
    • over_count
    • game_over_text
  17. What does this program print? a = 3 > 4 b = not a print(a) print(b)

    • False True
    • False False
    • True True
    • True False
  18. temp changes after freezing is set. What prints? temp = 10 freezing = temp <= 32 temp = 50 print(freezing)

    • True
    • TypeError
    • False
    • 10 >= 10
  19. In Python, the Boolean values True and False must be capitalized.

    True or false

  20. What does this program print? print(not 0)

  21. Which of these values are falsy in Python?

    • 0
    • "" (an empty string)
    • False
    • "False" (a non-empty string)
    • -1
  22. What does this program print? temp = 95 if temp > 90: print("Hot") print("Done")

    • Hot Done
    • Hot
    • Done
    • Done Hot
  23. What does this program print? temp = 60 if temp > 90: print("Hot") print("Done")

    • Done
    • Nothing is printed
    • Hot Done
    • Hot
  24. What does this program print? x = 3 if x > 5: print("A") print("B") print("C")

    • C
    • A B C
    • B C
    • Nothing is printed
  25. What does this program print? x = 3 if x > 5: print("A") print("B") print("C")

    • B C
    • C
    • A C
    • A B C
  26. What does this program print? age = 15 if age >= 16: print("Drive") else: print("Wait") print("Bye")

    • Wait Bye
    • Wait
    • Drive Wait Bye
    • Drive Bye
  27. What happens when this runs? x = 1 if x == 1 print("one")

    • SyntaxError
    • NameError
    • TypeError
    • one
  28. n is 0. What prints? n = 0 if n: print("non-zero") else: print("zero")

    • zero
    • non-zero
    • TypeError
    • Nothing is printed
  29. What does this program print? points = 10 if points > 5: points = points * 2 print(points)

    • 20
    • 10
    • 15
    • Nothing is printed
  30. What does this program print? points = 10 if points > 50: points = points * 2 else: points = points - 1 print(points)

    • 9
    • 20
    • 19
    • 10
  31. Two separate ifs change x. What is printed? x = 5 if x > 3: x = x - 4 if x > 3: x = x + 10 print(x)

    • 1
    • 11
    • 5
    • 15
  32. What does this program print? x = 2 if x > 3: x = x - 4 else: x = x + 10 if x > 3: x = x * 2 print(x)

    • 24
    • 2
    • 12
    • -2
  33. The user types kai (lowercase). What is printed? name = input("Name: ") if name == "Kai": print("Welcome back") else: print("Hello, stranger")

    • Name: kai Hello, stranger
    • Hello, stranger
    • Name: kai Welcome back
    • Name: kai
  34. Which program prints I can swim! when can_swim is True?

    • can_swim = True if can_swim: print("I can swim!") else: print("I can't swim.")
    • can_swim = True if can_swim print("I can swim!")
    • can_swim = True if not can_swim: print("I can swim!")
    • can_swim = True if can_swim = True: print("I can swim!")
  35. What does this program print? raining = True have_umbrella = False if raining: if have_umbrella: print("Walk") else: print("Wait") else: print("Walk")

    • Wait
    • Walk Wait
    • Walk
    • Nothing is printed
  36. A thermostat should print Heat on when temp is below 65 and do nothing otherwise. Which structure fits best?

    • A single if with no else
    • Two separate if statements that both print Heat on
    • An if/else whose else prints Heat on
    • An if/elif/else with three branches
  37. What does this program print? x = 10 if x > 5: print("big") else: print("small") print("check")

    • big
    • big check
    • small check
    • check
  38. What does this program print? x = 1 if x > 5: print("big") else: print("small") print("check")

    • small check
    • big check
    • small big check
    • small
  39. What does this program print? flag = False if not flag: flag = True if flag: print("on") else: print("off")

    • on
    • on off
    • Nothing is printed
    • off
  40. What does this program print? s = 7 if s > 0: print("a") if s > 5: print("b") else: print("c") print("d")

    • a b d
    • b d
    • a b c d
    • a d
  41. Which line runs no matter what value x has? x = int(input("x: ")) if x > 0: print("positive") print("checked") print("finished")

    • Line 5
    • Line 2
    • Line 4
    • Line 3
  42. Which change makes Wash your hands print only when hungry is True? hungry = True if hungry: print("Get a snack") print("Wash your hands")

    • Indent line 4 to line up with line 3
    • Change the if on line 2 into an elif
    • Add else: on its own line above line 4
    • Remove the colon at the end of line 2
  43. Every if statement must end with an else.

    True or false

  44. What does this program print? a = 4 b = 9 print(a < b, a >= b, a != b)

    • True False True
    • False False True
    • True True False
    • True False False
  45. What does this program print? print(10 <= 10, 10 < 10)

    • True False
    • True True
    • False True
    • False False
  46. What does this program print? print("apple" == "Apple")

    • False
    • True
    • apple
    • TypeError
  47. What does this program print? print(3 == 3.0)

    • True
    • TypeError
    • False
    • 3.0
  48. What does this program print? print("5" == 5)

    • False
    • 5
    • TypeError
    • True
  49. The user types 15. What happens? age = input("Age: ") print(age > 12)

    • Age: 15 TypeError
    • Age: 15 False
    • Age: 15 True
    • Age: 15 ValueError
  50. The user types 15. What is printed? age = int(input("Age: ")) print(age > 12)

    • Age: 15 True
    • True
    • Age: 15 TypeError
    • Age: 15 False

Showing 50 of 150. Open the quiz to study them all.