I am working on a multiple choice quiz. I want to be able to give user a chance to pick a valid option (a, b, or c) in case they chose a non-existent one (e.g. e). How do I get this done? At the moment, it goes right to the next quiz.
Here's a portion of my code:
def ask_question(question,score):
choices=('a','b','c')
print(question[0])
for multi in question[1:-1]:
print("{0:>5}{1}".format("",multi))
while True:
answer = input("Please select an answer: ")
if answer == question[-1] and answer in choices:
score += 1
elif answer not in choices:
print("Incorrect.Try again")
break
def main():
questions = get_questions()
score = 0
number = 10
print("Welcome to first quiz!")
print()
for next_question in range(number):
question = random.choice(questions)
score = ask_question(question, score)
questions.remove(question)
print("Your final score was {0} out of {1}.".format(score,number))
if score >= number * 0.75:
print("You have passed.")
else:
print("You have failed.")
if __name__ == "__main__":
main()