Python by Projects › Quiz Show

Exercises: Quiz Show

Take over the host's desk. You will score answers, repair bonus rules, remix sudden death, and predict what the scoreboard will show.

Exercise 1: Score the answers

Create three boolean variables named c1, c2, and c3. Give each one either True or False. Then add three separate if statements. Each true value should add 1 point with score = score + 1. Run the cell and inspect the scoreboard.

Real program

The real program reads whether each answer was correct with input(...) == "yes" instead of fixing the booleans.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 2: Fix the streak logic

Write this bonus check from scratch. Create correct and alive as boolean variables, begin with score = 3, and use and so 2 points are added only when both booleans are true. Try other True and False combinations after your first run.

Real program

The real program reads each boolean with input(...) == "yes".

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 3: Add a category bonus

Create score = 4, a category string, and a boolean named correct. If correct is true, add 1 point. Inside that if, add another if that awards 2 more points when category == "science". The category bonus must stay locked when the answer is wrong. Finish with an f-string scoreboard.

Real program

The real program reads correct and the category with input(...).

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 4: Sudden-death remix

Create your own three-question sudden-death round. Start an accumulator at score = 0, use asked = 0, and write a while asked < 3 loop. Inside it, use an if/elif/else chain keyed on counter values 0, 1, and 2 to ask exactly three hard-coded numeric questions with int(input(...)). Store each comparison result in a boolean named correct, then update the counter.

When correct is true, add 1 point. Nest another if inside that branch to print a special message after the third correct answer. A wrong answer must print a dramatic message and use break to end the round.

Write each question directly in its branch. Do not use lists, functions, or string methods.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 5: Error-message debugging

This host program is broken on purpose:

score = 2
bonus = input("Bonus points: ")
score = score + bonus
print(f"New score: {score}")

Run those lines in a temporary cell and type 3. Read the traceback from the bottom and write down its last line. Explain the two types Python tried to add. Then, in the code cell below, write the repaired program from scratch: use int(input(...)), update the score with the accumulator pattern, and print the new score.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 6: Predict the score

Cover the last print line. Trace the code on paper and predict the final score and the final value of asked. Pay special attention to the streak bonus and the point where break runs. Then uncover the line and run the cell to check.

This is a trace-and-predict exercise: it keeps fixed values on purpose so you can predict the output, so it has no input() version.

Starter (read-only)

score = 0
alive = True
first = True
second = True

if first:
    score = score + 1
else:
    alive = False

if second:
    score = score + 1
else:
    alive = False

if second and alive:
    score = score + 2

asked = 0
while asked < 3:
    if asked == 0:
        correct = True
    elif asked == 1:
        correct = False
    elif asked == 2:
        correct = True

    asked = asked + 1
    if correct:
        score = score + 1
    else:
        break

print(f"Score: {score}; questions asked: {asked}")

How this is checked: Checked by comparing your prediction with what the program really prints.

Answer format: one line

For parents and teachers: report a problem

Exercise 7: Escape the penalty loop

Some quiz shows punish coasting: if a player is not on a streak and gets an answer wrong, the player loses 1 point and the penalty round ends.

Write the whole round from scratch. Begin with score = 3, create boolean values for on_streak and correct, and enter a while True loop. Inside it, store a boolean named penalty using both not and and. If penalty is true, nest a score check inside that branch, subtract 1 point when the score is above 0, print the new score, and use break. Otherwise, print a safe message and use break so every path leaves the loop.

Real program

The real program reads on_streak and correct with input(...) == "yes".

More Practice — homework after Lesson 3

These exercises mix all four Quiz Show ideas.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 8: Accept either spelling

Build a retry round that accepts either "true" or "True". Start score and attempts at 0, then use a while attempts < 3 loop. Each trip asks for a string answer, increases attempts, and stores the full or comparison in a boolean named accepted.

If accepted is true, add 1 point. Nest another if inside that branch to add 1 more point when the player succeeded on the first attempt, then print the score and use break. If the third attempt is wrong, print an ending message and use break. Write the complete program yourself; do not use string methods.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 9: Two strikes

Create three boolean answer results and a round controlled by q = 0. Also create score = 0 and strikes = 0. Use a while q < 3 loop and an if/elif/else chain to choose the boolean result for that question.

Use the not operator to check for a wrong answer, then add 1 to strikes. Nest another if inside that branch: when strikes == 2, print "Two strikes — game over!" and use break. In the outer else branch, add 1 point to score for a correct answer. Update the question counter each trip and print both totals at the end.

Real program

The real program reads each answer with input(...) == "yes" as the loop runs.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 10: Last-chance qualifier

Write a two-attempt qualifier. Ask for a starting score with int(input(...)), then begin attempts = 0. Use a while attempts < 2 loop to ask a hard-coded numeric question with int(input(...)), update the counter, and store the comparison result in a boolean named correct. Also store eligible = correct and score >= 4. A correct answer can now fail the score requirement, and a player with enough points can still fail the answer requirement.

If eligible is true, nest an if that awards 2 points on the first attempt and 1 point on the second attempt, then print a victory message and use break. Otherwise, nest a check that subtracts 1 point only when the answer was wrong. After any unqualified second attempt, print a closing message and use break. Print the final score after the loop. For example, starting with 5 points, missing once, and then answering correctly must qualify on attempt 2.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

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.

Exercise 11: Running total: add the round scores

A quiz can have any number of rounds. Write a program that first reads how many rounds there are, then reads the score for each of those rounds. Start with total = 0 and r = 0; use a counter-bounded while r < rounds loop that reads one score each pass with int(input(...)), adds it with total = total + score, and updates the counter. After the loop, print the total. Your program must work for any number of rounds — a short quiz of 4 rounds or a long one of 10, not just 3.

Do not use a list, for, range, functions, or string methods.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 12: Count the correct answers

Write a program that first reads how many answers there are, then reads each answer result. Start q = 0 and count = 0 and use a counter-bounded while q < answers loop. Each pass reads one result with input(...) == "yes"; when it is true, bump count by 1. Update q every trip, then print the number of correct answers after the loop. Your program must work for any number of answers — not just the five in the checked example.

Do not use a list, for, range, functions, or string methods.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 13: Correct and wrong tally

Step through the five fixed answers True, False, True, True, False with a counter-bounded while loop and an if/elif/else chain that picks each answer in turn. Keep separate counters for correct and wrong answers, then print both counts.

Real program

The real program reads how many answers there are, then reads each with input(...) == "yes".

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 14: Add only the passing rounds

Step through the five fixed scores 4, 6, 5, 7, 3 with a counter-bounded while loop and an if/elif/else chain that picks each score in turn. Add a score to the running total only when it is at least 5, then print the final total.

Real program

The real program reads how many scores there are, then reads each with int(input(...)).

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 15: Points and penalties

Step through the five fixed answers True, False, True, True, False with a counter-bounded while loop and an if/elif/else chain that picks each answer in turn. Add 2 points when it is correct and subtract 1 when it is wrong, then print the final total.

Real program

The real program reads how many answers there are, then reads each with input(...) == "yes".

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 16: Opening streak

Step through the five fixed answers True, True, True, False, True with a counter-bounded while loop and an if/elif/else chain that picks each answer in turn. Count the opening streak of correct answers and use break to stop at the first wrong answer, then print the streak count.

Real program

The real program reads how many answers there are, then reads each with input(...) == "yes", stopping at the first wrong one.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 17: Scores that fit the budget

Step through the five fixed scores 4, 6, 5, 7, 3 with a counter-bounded while loop and an if/elif/else chain that picks each score in turn, with the budget set to 12. Check before adding: add a score only if the new total would stay at or below the budget, and otherwise stop. Print the fitting total and how many scores fit.

Real program

The real program reads how many scores there are, then reads each with int(input(...)).

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 18: Scores until the budget tips

Step through the same five fixed scores 4, 6, 5, 7, 3 with a counter-bounded while loop and an if/elif/else chain that picks each score in turn, with the budget set to 12. Add then check: add each score first, then stop as soon as the total goes above the budget. Print the tipping total, how many scores were added, and which round tipped it.

Real program

The real program reads how many scores there are, then reads each with int(input(...)).

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Exercise 19: Add scores until the player types 0

Homework: Use int(input(...)) to read one score at a time and keep a running total in a while loop, stopping when the player enters 0; then print the total. Worked example: entering 5, 3, 8, then 0 adds 3 scores for a total of 16.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Challenge

Try these after the earlier exercises.

Challenge 1: Double or Nothing

  • Challenge

Begin with score = 4. Ask whether the player wants to risk those points. Only if the player types yes, ask one hard-coded question. If that answer is correct, double the score with arithmetic. If it is wrong, set the score to 0. If the player does not type yes, keep the original score. Use nesting so the quiz question exists only inside the risk choice.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Challenge 2: Lightning-Round Countdown

  • Challenge

Make a visible countdown from 5 to 1 with a while loop. Start with seconds_left = 5. Each trip should print the counter, then update it with seconds_left = seconds_left - 1. After the loop, print Time!. This uses the counter idea from Unit 03; it does not need a new kind of collection or helper.

A countdown reads nothing from the player — it just counts down — so this one has no input() version.

How this is checked: You check this one yourself, against the list below.

The site cannot check this one. Run your program, then tick each item below when your work does it.

Check your work

For parents and teachers: report a problem

Back to Quiz Show