class Question:
def __init__(self, prompt, answer):
self.prompt = prompt
self.answer = answer
I created the question_class.py file above and imported it into the quiz.py file below. I am trying to run a while loop to ask the user whether they are interested in playing the quiz again. However, the code does not run.
How do I properly insert a play again while loop? Also, how do I ask if the user is ready to play the game and properly check for input errors?
This is my first individual project and trying to learn how to code my own project after completing a beginners tutorial. I appreciate all feedback.
from question_class import Question
username = input("What is your name? ")
print(f"Welcome, {username}!")
play_again = 'y'
while play_again == 'y':
question_prompts = [
]
questions = [
Question(question_prompts[0], "b"),
Question(question_prompts[1], "a"),
]
def run_test(questions):
score = 0
for question in questions:
answer = input(question.prompt)
if answer == question.answer:
score += 1
print("You answered " + str(score) + "/" + str(len(questions)) + " correct.")
play_again = input("Want to play again(y/n): ")
run_test(questions)