Python Editor

Python | Applications | Quiz App


class Question: def __init__(self, prompt, answer): self.prompt = prompt self.answer = answer # Define a list of questions questions = [ Question("What is the capital of France?\n(a) Paris\n(b) Rome\n(c)
Madrid\n\n", "a"), Question("Which programming language is known for its readability?\n(a) Java\n(b)
Python\n(c) C++\n\n", "b"), Question("What symbol is used to indicate the start of a comment in Python?\n(a)
//\n(b) /*\n(c) #\n\n", "c") ] # Function to run the quiz def run_quiz(questions): score = 0 for question in questions: answer = input(question.prompt) if answer.lower() == question.answer.lower(): score += 1 print("You got " + str(score) + "/" + str(len(questions)) + " correct!") # Run the quiz run_quiz(questions)



No comments:

Post a Comment