Simple Python Games: Trivia Game

Source code of trivia.py

from time import sleep

questions = (
    #("question", (answers), index_of_correct_answer),
    ("What is the name of the nearest star?", ("Venus", "Sun", "Moon"), 1),
    ("What is the name of the capital city of Sweden?", ("Oslo", "Paris", "Stockholm", "Helsinki"), 2),
)

print()
print("Trivia game! (Ctrl+C to exit)")
print()

for question, answers, correct in questions:
    print()
    print(question)
    for num, answer in enumerate(answers):
        print(num+1, answer)
    print()
    player_answer = input("Enter the number of the answer: ")
    sleep(2)
    print()
    if player_answer == str(correct + 1):
        print("You are right!")
    else:
        print("Not correct.")
    print("The answer is", answers[correct])
    print()
    sleep(5)

Tips for improvement

  1. Add more questions
  2. Add an "exit" option handling instead of Ctrl+C
  3. Randomize order of questions
  4. Show the player score
  5. Add the "50 to 50" option

Download

Source code of Trivia Game (trivia.py).