Exit slides Esc

Quiz Show

Slide 1 of 45

  1. The lights flash. The audience cheers. You are about to host a quiz show with scores, streak bonuses, secret follow-ups, and a SUDDEN DEATH round. Can your code keep the whole game fair?

    Each idea comes as a short ladder — the simplest version, then one small step up, then the real game use — with a Notice naming the one new thing each time.

    • Keep a running score with the accumulator pattern.

    • Combine yes/no facts with and, or and not.

    • Nest one if inside another for a secret follow-up question.

    • End a loop early with break.

  2. Lesson 1: Score and Streaks

    A quiz needs a score that can grow. An accumulator is a variable that collects a total: score = score + 1 takes the old value, adds one, and stores it back.

  3. score = 0
    score = score + 1
    print(f"Score: {score}")

    Output

    Score: 1
    

    score = score + 1 turns the old 0 into 1 and saves it back in score.

  4. score = 0
    score = score + 1
    score = score + 1
    print(f"Score: {score}")

    Output

    Score: 2
    

    Each update builds on the last, so the total climbs to 2.

  5. score = 0
    r = 0
    while r < 3:
        score = score + 1
        r = r + 1
    print(f"Score after the round: {score}")

    Output

    Score after the round: 3
    

    Inside a while loop the accumulator grows once per trip — three trips, three points.

  6. score = 0
    asked = 0
    r = 0
    while r < 3:
        asked = asked + 1
        score = score + 1
        r = r + 1
    print(f"Asked {asked}, scored {score}")

    Output

    Asked 3, scored 3
    

    Two accumulators can run side by side — points earned versus questions asked — each answering its own question.

  7. A quiz also needs rules that combine yes/no facts. Logical operators join booleans: and, or, not.

  8. print(True and True)
    print(True and False)

    Output

    True
    False
    

    and is True only when BOTH sides are True.

  9. print(True or False)
    print(False or False)

    Output

    True
    False
    

    or is True when AT LEAST ONE side is True.

  10. print(not True)
    print(not False)

    Output

    False
    True
    

    not flips True and False.

  11. correct = True
    alive = True
    print(correct and alive)

    Output

    True
    

    Combine them for a real rule — the streak bonus needs the answer correct and the streak alive.

  12. Here is the opening round put together. With fixed stand-in answers it runs top to bottom; the real version below reads what the player actually types.

  13. score = 0
    asked = 0
    alive = True
    
    answer_1 = 8  # Fixed stand-in for the typed answer.
    asked = asked + 1
    if answer_1 == 8:
        score = score + 1
    else:
        alive = False
    
    answer_2 = "Pacific"  # Fixed stand-in for the typed answer.
    asked = asked + 1
    if answer_2 == "Pacific" or answer_2 == "pacific":
        score = score + 1
    else:
        alive = False
    
    if answer_1 == 8 and alive:
        score = score + 1
        print("Streak bonus!")
    
    print(f"Score {score} after {asked} questions.")

    Output

    Streak bonus!
    Score 3 after 2 questions.
    
  14. With fixed stand-in answers the opening round runs top to bottom — accumulators keep the tallies, or accepts either spelling, and and guards the bonus (score 3).

  15. Try it
    score = 0
    asked = 0
    alive = True
    
    answer_1 = int(input("What is 5 + 3? "))
    asked = asked + 1
    if answer_1 == 8:
        score = score + 1
    else:
        alive = False
    
    answer_2 = input("Which ocean is west of California? Type Pacific: ")
    asked = asked + 1
    if answer_2 == "Pacific" or answer_2 == "pacific":
        score = score + 1
    else:
        alive = False
    
    if answer_1 == 8 and alive:
        score = score + 1
        print("Streak bonus!")
    
    print(f"Score {score} after {asked} questions.")
  16. The real version reads each answer with input() — same rules, live answers. (It reads live input, so it does not run here.)

  17. Lesson 2: Secret Follow-ups

    A condition can live inside another condition. This is conditional nesting: the inner if is reached only when the outer if is True.

  18. unlocked = True
    correct = True
    if unlocked:
        if correct:
            print("Bonus won!")

    Output

    Bonus won!
    

    The inner if runs only because the outer if (unlocked) was True.

  19. unlocked = True
    correct = False
    if unlocked:
        if correct:
            print("Bonus won!")
        else:
            print("Unlocked, but the answer was wrong.")

    Output

    Unlocked, but the answer was wrong.
    

    The inner if/else lives entirely inside the outer branch.

  20. score = 0
    unlocked = True
    correct = True
    if unlocked:
        if correct:
            score = score + 1
    print(f"Score: {score}")

    Output

    Score: 1
    

    One new step — the inner branch now DOES something (scores a point) instead of just printing.

  21. Now put the whole follow-up together: part one must be right to unlock a scored part two.

  22. part_one = 12
    final_score = 0
    if part_one == 12:
        final_score = final_score + 1
        part_two = "Saturn"
        if part_two == "Saturn":
            final_score = final_score + 2
            print("Follow-up bonus!")
        else:
            print("Follow-up missed.")
    else:
        print("The follow-up stays locked.")
    print(f"Final score: {final_score}")

    Output

    Follow-up bonus!
    Final score: 3
    

    The follow-up stays locked unless part one is correct — a gate inside a gate.

  23. Try it
    part_one = int(input("Part one answer: "))
    final_score = 0
    if part_one == 12:
        final_score = final_score + 1
        part_two = input("Follow-up answer: ")
        if part_two == "Saturn":
            final_score = final_score + 2
            print("Follow-up bonus!")
        else:
            print("Follow-up missed.")
    else:
        print("The follow-up stays locked.")
    print(f"Final score: {final_score}")

    The real program reads the two answers with input() — everything else is the same gate-inside-a-gate. (It reads live input, so it does not run here.)

  24. Lesson 3: SUDDEN DEATH

    In the final round, one wrong answer ends everything. A break statement leaves a loop immediately, jumping to the first line after it.

  25. count = 0
    while count < 5:
        print(count)
        if count == 2:
            break
        count = count + 1

    Output

    0
    1
    2
    

    break stops the loop the instant count reaches 2 — it never prints 3 or 4.

  26. r = 0
    while r < 3:
        correct = r != 1
        if not correct:
            print("Wrong — round over!")
            break
        print("Correct! Keep going.")
        r = r + 1

    Output

    Correct! Keep going.
    Wrong — round over!
    

    A wrong answer triggers break, ending the whole round early.

  27. streak = 0
    r = 0
    while r < 10:
        streak = streak + 1
        if streak == 3:
            print("Three in a row — banking it!")
            break
        r = r + 1

    Output

    Three in a row — banking it!
    

    One new step — here break fires when an accumulator (streak) reaches a target, not on a wrong answer.

  28. Now put it together as the full SUDDEN DEATH round. With fixed stand-in answers it runs top to bottom; the real version below reads what the player types.

  29. asked = 0
    score = 0
    
    while asked < 3:
        if asked == 0:
            answer = 3  # Fixed stand-in for the typed answer.
            correct = answer == 3
        elif asked == 1:
            answer = 42  # Fixed stand-in for the typed answer.
            correct = answer == 42
        else:
            answer = 7  # Fixed stand-in for the typed answer.
            correct = answer == 7
    
        if not correct:
            print("Wrong! Sudden death ends.")
            break
        score = score + 1
        asked = asked + 1
    
    print(f"Survived {score} sudden-death questions.")

    Output

    Survived 3 sudden-death questions.
    
  30. With fixed correct answers the round runs to the end — a while loop, an if/elif/else dispatch, and break ready the instant an answer is wrong (survived 3).

  31. Try it
    asked = 0
    score = 0
    
    while asked < 3:
        if asked == 0:
            answer = int(input("SUDDEN DEATH 1 — sides on a triangle? "))
            correct = answer == 3
        elif asked == 1:
            answer = int(input("SUDDEN DEATH 2 — 6 times 7? "))
            correct = answer == 42
        else:
            answer = int(input("SUDDEN DEATH 3 — days in a week? "))
            correct = answer == 7
    
        if not correct:
            print("Wrong! Sudden death ends.")
            break
        score = score + 1
        asked = asked + 1
    
    print(f"Survived {score} sudden-death questions.")
  32. The real version reads each answer with input() and breaks the moment one is wrong. (It reads live input, so it does not run here.)

  33. Algorithm Extension

    Extra loop practice — optional enrichment: these drills reuse the same loop shapes on small fixed data, so try as many as you like.

  34. Pattern Spotlight: Running total (accumulate)

    When values arrive one at a time, the program needs a named box holding the total-so-far, updated each step.

    A counter says how many rounds; a running total says how many points altogether.

  35. total = 0
    total = total + 5
    print(total)

    Output

    5
    

    Start the running total at 0, then add the first score — the box now holds 5.

  36. total = 0
    total = total + 5
    total = total + 3
    print(total)

    Output

    8
    

    Each new score builds on the total-so-far, so it climbs to 8.

  37. r = 1
    total = 0
    while r <= 3:
        if r == 1:
            score = 5
        elif r == 2:
            score = 3
        else:
            score = 8
        total = total + score
        r = r + 1
    print(total)

    Output

    16
    

    The loop feeds one score per round into the SAME running total — 5, then 8, then 16.

  38. Try it
    rounds = int(input("How many rounds? "))
    total = 0
    r = 1
    while r <= rounds:
        score = int(input(f"Score for round {r}: "))
        total = total + score
        r = r + 1
    print(total)

    The same running total, now fed by however many scores the player types — swap the fixed rounds for input() and it works for any number of rounds. (Reads live input, so it does not run here.)

  39. Pattern Spotlight: Counting by condition (count)

    Keep a counter; check each item once, bump it when it matches.

    A running total adds each value; counting by condition adds exactly 1 only when the check says yes.

  40. count = 0
    score = 7
    if score >= 5:
        count = count + 1
    print(count)

    Output

    1
    

    The counter moves only when the check passes — 7 >= 5 is True, so count becomes 1.

  41. count = 0
    score = 7
    if score >= 5:
        count = count + 1
    score = 3
    if score >= 5:
        count = count + 1
    print(count)

    Output

    1
    

    Check each score once; 7 passes but 3 fails, so only one is counted.

  42. r = 1
    count = 0
    while r <= 3:
        if r == 1:
            score = 7
        elif r == 2:
            score = 3
        else:
            score = 8
        if score >= 5:
            count = count + 1
        r = r + 1
    print(count)

    Output

    2
    

    One pass over the rounds, adding 1 only when a score clears 5 — 7 and 8 pass, 3 does not, so 2.

  43. Try it
    rounds = int(input("How many rounds? "))
    r = 1
    count = 0
    while r <= rounds:
        score = int(input(f"Score for round {r}: "))
        if score >= 5:
            count = count + 1
        r = r + 1
    print(count)

    The counter still bumps only when a score clears 5, but now it reads each score with input() and works for any number of rounds. (Reads live input, so it does not run here.)

    • score = score + 1 takes the old total, adds one and saves it back.

    • and needs both sides True, or needs at least one, and not flips a boolean.

    • A nested if is reached only when the outer if is True.

    • break leaves a loop at once and jumps to the first line after it.

    You can now host a quiz show with a score, a streak bonus and a SUDDEN DEATH round.