Ask coding questions

← Back to all posts
How to add limited hints when programming a quiz
seohyeonl (0)

I am making a trivia quiz that allows users to solve 10 trivia questions and get a score. I am planning to provide the users 3 hints and print out "Sorry! You used all the hints." when the user uses all 3 hints. How do I do that? I know I would need to use while loop but when I used it, it does not limit the number of hints the user can get...
Can you please help me by looking at my code?
Thank you.

Codejira (173)

There's a lot to improve. As a rule of thumb: Don't repeat yourself!

Consider another structure where you put your questions in a list, so that you can loop over them.

Then it's easy to keep track of the hints:

hints = 0
for q in questions:
    if answer == "hint":
        if hints < 3:
            print("Here's a hint: ...")
            hints += 1
            print("No more hints for you!")