True or False Trivia Challenge Python Script

This interactive quiz game lets you explore fun categories by answering unique True/False questions. With each question, you’ll receive immediate feedback and an insightful explanation to expand your knowledge.

Click to view script…
#!/usr/bin/env python3
import random

def main():
    categories = {
        "1": {
            "name": "Animal Trivia",
            "questions": [
                {
                    "question": "Elephants are the only animals that can't jump.",
                    "answer": True,
                    "description": "True! Due to their massive weight and unique limb structure, elephants are physically incapable of jumping."
                },
                {
                    "question": "Bats are blind.",
                    "answer": False,
                    "description": "False! While bats use echolocation, they also have functional eyes and can see."
                },
                {
                    "question": "A group of flamingos is called a 'flamboyance'.",
                    "answer": True,
                    "description": "True! The collective noun for flamingos is indeed 'flamboyance', which suits their vibrant appearance."
                },
                {
                    "question": "An octopus has three hearts.",
                    "answer": True,
                    "description": "True! Octopuses have two branchial hearts and one systemic heart."
                },
                {
                    "question": "Goldfish have a memory span of just three seconds.",
                    "answer": False,
                    "description": "False! Goldfish can actually remember things for months."
                }
            ]
        },
        "2": {
            "name": "Space Facts",
            "questions": [
                {
                    "question": "A day on Venus is longer than its year.",
                    "answer": True,
                    "description": "True! Venus rotates very slowly, making its day longer than the time it takes to orbit the Sun."
                },
                {
                    "question": "There is no sound in space.",
                    "answer": True,
                    "description": "True! Space is a vacuum, so sound cannot travel."
                },
                {
                    "question": "Mars has the tallest volcano in the solar system, Olympus Mons.",
                    "answer": True,
                    "description": "True! Olympus Mons on Mars stands about 22 kilometers high, making it the tallest volcano known."
                },
                {
                    "question": "Saturn is the only planet with rings.",
                    "answer": False,
                    "description": "False! While Saturn’s rings are the most prominent, Jupiter, Uranus, and Neptune also have ring systems."
                },
                {
                    "question": "The footprints on the Moon will disappear over time due to wind erosion.",
                    "answer": False,
                    "description": "False! The Moon has no atmosphere or wind, so the footprints will likely remain for millions of years."
                }
            ]
        },
        "3": {
            "name": "History Myths",
            "questions": [
                {
                    "question": "Napoleon Bonaparte was extremely short.",
                    "answer": False,
                    "description": "False! Napoleon was of average height for his era; the myth of his short stature comes from a misunderstanding of French measurements."
                },
                {
                    "question": "The Great Wall of China is visible from space.",
                    "answer": False,
                    "description": "False! The Great Wall is very narrow and follows the natural contours of the land, making it nearly impossible to see from space with the naked eye."
                },
                {
                    "question": "Vikings wore horned helmets.",
                    "answer": False,
                    "description": "False! There is no historical evidence that Vikings ever wore horned helmets; this image was popularized by 19th-century artists."
                },
                {
                    "question": "The French Revolution began in 1789.",
                    "answer": True,
                    "description": "True! The French Revolution, which reshaped France and influenced modern democracies, began in 1789."
                },
                {
                    "question": "Christopher Columbus made his first voyage to the Americas in 1492.",
                    "answer": True,
                    "description": "True! In 1492, Columbus set sail, marking the beginning of European exploration of the Americas."
                }
            ]
        }
    }

    print("Welcome to the True/False Quiz Game!")
    
    while True:
        print("\nChoose a category for your quiz:")
        for key, cat in categories.items():
            print(f"{key}. {cat['name']}")
        print("Q. Quit")
        
        choice = input("Enter your choice: ").strip().lower()
        if choice == 'q':
            print("Thanks for playing! Goodbye!")
            break
        
        if choice not in categories:
            print("Invalid choice. Please try again.")
            continue
        
        selected_cat = categories[choice]
        print(f"\nYou selected: {selected_cat['name']}")
        # Create a local copy of the questions list so each question is shown only once.
        available_questions = selected_cat["questions"].copy()
        
        while available_questions:
            question = random.choice(available_questions)
            available_questions.remove(question)
            
            print("\n" + question["question"])
            user_answer = input("Type T for True or F for False: ").strip().lower()
            
            if user_answer not in ["t", "f"]:
                print("Invalid input. Please type 'T' or 'F'.")
                continue
            
            user_bool = True if user_answer == "t" else False
            
            if user_bool == question["answer"]:
                print("Correct!")
            else:
                print("Incorrect!")
            
            print("Explanation:", question["description"])
            
            # Check if there are more questions available.
            if available_questions:
                another = input("\nWould you like another question from this category? (y/n): ").strip().lower()
                if another != "y":
                    break
            else:
                print("\nNo more questions left in this category.")
                
if __name__ == "__main__":
    main()