import getpass
def ask_question(question, options, correct_option):
print(question)
for i, option in enumerate(options, start=1):
print(f"{i}. {option}")
while True:
try:
user_choice = int(input("Enter the number of your choice: "))
if 1 <= user_choice <= len(options):
break
else:
print("Invalid choice. Please enter a valid number.")
except ValueError:
print("Invalid input. Please enter a number.")
if user_choice == correct_option:
print("Correct!\n")
return True
else:
print(f"Sorry, that's incorrect. The correct answer is: {options[correct_option-1]}\n")
return False
questions = [
{
"question": "Which team holds the record for the most Premier League titles?",
"options": ["1. Manchester United", "2. Liverpool", "3. Chelsea", "4. Arsenal"],
"correct_option": 1,
},
{
"question": "Who is the all-time top scorer in Premier League history?",
"options": ["1. Wayne Rooney", "2. Alan Shearer", "3. Thierry Henry", "4. Frank Lampard"],
"correct_option": 1,
},
{
"question": "Which club won the Premier League in the 2020-2021 season?",
"options": ["1. Liverpool", "2. Manchester City", "3. Manchester United", "4. Chelsea"],
"correct_option": 2,
},
]
score = 0
for question_data in questions:
if ask_question(question_data["question"], question_data["options"], question_data["correct_option"]):
score += 1
print("Premier League Facts Quiz completed! Your score is:", score, "out of", len(questions))
Python Quiz • 2 min read
Description
Quiz coded on Python