I've been playing about with this for a few hours now and have tried a few variations and am still getting nowhere and am not sure what I'm getting wrong. I'm trying to make it so users can only give input values of a, b or c. If anyone could advise that would be greatly appreciated. Thanks.
def run_quiz(questions):
"""
Function loops through questions and checks answer given
against correct answer. If correct answer given
then score increases by 1.
"""
score = 0
for question in questions:
answer = input(question.prompt)
answer = answer.lower()
if answer == question.answer:
score += 1
while answer not in {'a', 'b', 'c'}:
return "Invalid answer, try again"
else:
return f"You guessed {answer}"
print(f"{name} got {score} out of {str(len(questions))} questions correct")