-1

So, i have been learning from a video on youtube about basic multiple choice quiz with few possilble answers like a, b, c. but, if the user enters r or 44 the code just wont count it as a right answer. I want the code to print the user the question again. Ive tried to write something but now it is moving on to the next question only if the user enters the right question.

def test_run2(questions):
score = 0
for question in questions:
    while  True:
        user_answer = input(question.prompt)
        user_answer.lower()
        if user_answer == "a" or "b" or "c":
            if user_answer == question.answer:
                score = score + 1
            break
  • 3
    `if user_answer == "a" or "b" or "c":` is not how to compare multiple values. You can use `if user_answer in ["a", "b", "c"]:` [How to test multiple variables against a single value?](https://stackoverflow.com/a/15112149) – 001 Nov 08 '21 at 21:19
  • Thanks it worked – ZeusTheMotek Nov 08 '21 at 21:33
  • `user_answer.lower()` returns a lower-case version of your string, which you immediately discard. Instead, combine with previous line: `user_answer = input(question.prompt).lower()` – khelwood Nov 08 '21 at 21:35

1 Answers1

1
# For each of your questions
running = True
while running:
    print("") # Put question in here
    if answer in possibleAnswers:
        # Check if correct or wrong, etc.
        running = False
    else:
        print("Please provide a valid answer")
# Repeat again for next question

Note that this is just a snippet, you need to add the other sections of your code to it where applicable.

Larry the Llama
  • 958
  • 3
  • 13