Text-based Quiz App (code) in Python

← Back to Projects

Text-based Quiz App in Python.

About the project: This quiz app will present a series of questions to the user.

The user will input their answers, and the program will keep track of their score, displaying the final results at the end.

You can easily customize the questions and answers to create a quiz on any topic you like.

You can easily modify the questions list in the code to create your own quizzes on any topic. Each dictionary in the list represents a question, and you can change the question text, options, and the correct answer accordingly.

How to use this Text-based Quiz App :

  • Run the Python script.
  • The program will present each question and its multiple-choice options.
  • It will then prompt you to enter the currency to convert from, the currency to convert to, and the amount.
  • Type the letter (A, B, C, or D) corresponding to your answer and press Enter.
  • After answering all the questions, the program will display your final score and percentage.


Project Level: Beginner

You can directly copy the below snippet code with the help of green copy button, paste it and run it in any Python editor you have.

Steps: Follow these steps

Step 1: Copy below code using green 'copy' button.

Step 2: Paste the code on your chosen editor.

Step 3: Save the code with filename and .py extention.

Step 4: Run (Press F5 if using python IDLE)




# quiz_app.py

def run_quiz():
    """
    Runs a text-based quiz, keeps score, and displays the final result.
    """
    questions = [
        {
            "question": "What is the capital of France?",
            "options": ["A. London", "B. Paris", "C. Berlin", "D. Rome"],
            "answer": "b"
        },
        {
            "question": "Which planet is known as the Red Planet?",
            "options": ["A. Jupiter", "B. Mars", "C. Venus", "D. Saturn"],
            "answer": "b"
        },
        {
            "question": "What is the largest ocean on Earth?",
            "options": ["A. Atlantic Ocean", "B. Indian Ocean", "C. Arctic Ocean", "D. Pacific Ocean"],
            "answer": "d"
        },
        {
            "question": "What is the chemical symbol for gold?",
            "options": ["A. Au", "B. Ag", "C. Gd", "D. Ge"],
            "answer": "a"
        },
        {
            "question": "What is the highest mountain in the world?",
            "options": ["A. K2", "B. Mount Kilimanjaro", "C. Mount Everest", "D. Mount Fuji"],
            "answer": "c"
        }
    ]

    score = 0
    total_questions = len(questions)

    print("--- Welcome to the Quiz App! ---")
    print("Answer the following questions by typing the letter of the correct option.")
    print("---------------------------------")

    for q in questions:
        print(f"\n{q['question']}")
        for option in q['options']:
            print(option)
        
        user_answer = input("Your answer: ").strip().lower()

        if user_answer == q['answer']:
            print("Correct!")
            score += 1
        else:
            print(f"Incorrect. The correct answer was {q['answer'].upper()}.")

    print("\n--- Quiz Finished ---")
    print(f"You got {score} out of {total_questions} questions correct.")
    print(f"Your final score is: {score / total_questions * 100:.2f}%")
    print("---------------------")

# This ensures that run_quiz() is called only when the script is executed directly.
if __name__ == "__main__":
    run_quiz()