0

I programmed a multiple choice quiz. Here is my code:

questions = {1: "a", 2: "c", 3: "b", 4: "d", 5: "e"}

def trivia():
  score = 0

  for i in questions:
    print(i)
    answer = input("Answer: ").lower()
    if answer == questions[i]:
      print("You got it right.")
      score = score + 10

    else:
      print("You got it wrong.")
      score = score - 10

  print("Your score is: " + str(score))

trivia()

This is what I want to add to my quiz:

  1. 3 hints in total →

    I want to provide users 3 hints on any question when they are solving the quiz. For example, if the user got stuck on the first trivia question, the user can type 'hint' or 'h' next to "Answer: " and get a hint for the first question.

    Only one hint for each question. Let's say the user used his other hints for the second question and the third question and asked for another hint on the fourth question. Then, I want to print "no hints available" and let the user answer the question without providing any hint for the fourth question. And the user will not be able to get any hints for the fifth question.

  2. I also have to use continue and break but I don't know where to use them.

martineau
  • 119,623
  • 25
  • 170
  • 301
cherry123
  • 49
  • 4
  • Please repeat [on topic](https://stackoverflow.com/help/on-topic) and [how to ask](https://stackoverflow.com/help/how-to-ask) from the [intro tour](https://stackoverflow.com/tour). “Show me how to design my homework” is not a Stack Overflow issue. We expect you to make an honest attempt, and *then* ask a *specific* question about your algorithm or technique. Stack Overflow is not intended to replace existing documentation and tutorials. – Prune Apr 06 '21 at 00:22
  • Also see Stack Overflow guidance on [homework](https://meta.stackoverflow.com/questions/334822/how-do-i-ask-and-answer-homework-questions). Simply dumping your assignment here is unacceptable, and is likely a violation of your school's academic honesty policies. – Prune Apr 06 '21 at 00:22
  • @Prune I am not dumping my assignment. I tried so many times but they just didn't work at all. Can you at least tell me what type of loop or method I need to use to add limited hints? I have no other places to ask because my computer teacher does not answer my questions. – cherry123 Apr 06 '21 at 00:36
  • 1
    I think you could modify one of the techniques show in the answers to [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) to do what you want. For example you could keep track of how many times they have answered incorrectly and start providing hints based on that. – martineau Apr 06 '21 at 00:47
  • 1
    Please go through the [intro tour](https://stackoverflow.com/tour), the [help center](https://stackoverflow.com/help) and [how to ask a good question](https://stackoverflow.com/help/how-to-ask) to see how this site works and to help you improve your current and future questions, which can help you get better answers. Stack Overflow is not an individual help desk or tutorial service. "I have no other places to ask" is incorrect. You seem to have a broader range of needs than we deal with here; you might try looking for a general Q&A site for such help. – Prune Apr 06 '21 at 01:03
  • 1
    Try using the flowcharting method: draw a diagram of the steps your user can work through. Write a short code block to handle asking for a hint, and wrap that in a function you can call. Put together little blocks of solutions, until you have enough for you to see the whole picture. – Prune Apr 06 '21 at 01:04
  • One side note: you seem to have the responsibility flow out of order: you and your instructor have primary responsibility for getting answers to your questions. If your instructor refuses to answer, you need to elevate the problem to the institution. After that, you have normal research (on-line tutorials and examples) and open help sites. Stack Overflow is a last resort (as the posting guidelines tell you), not front-line support for your class. – Prune Apr 06 '21 at 01:07
  • You have asked a variety of questions here, some of the issues being open-ended. Both of these characteristics are off-topic for Stack Overflow. I'm not trying to yell at you: I want you to use the proper resource for each problem. Once you've reviewed the SO posting guidelines and focused your needs, I expect that you'll have one or two good questions for us, rather than one umbrella posting. – Prune Apr 06 '21 at 01:08

0 Answers0