Simple Quiz program using Python

 Simple Quiz app using Python

This Python program is a fun and interactive quiz game designed to help users test their knowledge and have an enjoyable learning experience. To get started, the program asks the user to enter their name for a personalized touch. It then proceeds to present three thought-provoking multiple-choice questions, covering a range of topics, including geography, astronomy, and general knowledge.

The user can easily modify the program by adjusting the 'questions' list to create their own custom quizzes. This flexibility allows users to tailor the quiz to their specific interests or educational goals. They can add more questions or even change the correct answers to test themselves or challenge friends on a variety of subjects.

As the user engages with this program, they not only get to test their knowledge but also gain valuable insights into Python programming. The code demonstrates the use of lists, dictionaries, user input, conditional statements, and loops, making it a fantastic learning tool for beginners in Python. By creating and running this program, users can develop a better understanding of Python's fundamental concepts while having fun and learning something new along the way. It's a great way to introduce programming concepts in a user-friendly and engaging manner. So, whether you're a beginner looking to learn Python or someone who loves quizzes, this program is an excellent choice to explore and enjoy the world of coding.

import random

print("Answer 3 simple questions and check your score")
userName = input("Enter your name: ")

questions = [
    {
        "question": "Q1. What is the capital of France?",
        "options": ["a. Paris", "b. London"],
        "correct_answer": "a",
    },
    {
        "question": "Q2. Which planet is known as the 'Red Planet'?",
        "options": ["a. Mars", "b. Venus"],
        "correct_answer": "a",
    },
    {
        "question": "Q3. How many continents are there on Earth?",
        "options": ["a. 7", "b. 5"],
        "correct_answer": "a",
    },
]

total = len(questions)
score = 0
correctAnswer = 0
wrongAnswer = 0

random.shuffle(questions)  # Randomize question order

for question in questions:
    print(question["question"])
    for option in question["options"]:
        print(option)
    
    ans = input("Enter your choice (a/b): ").strip().lower()
    
    if ans == question["correct_answer"]:
        correctAnswer += 1
        score += 1
    else:
        wrongAnswer += 1

print("_" * 30)
print("Name:", userName)
print("Score:", score, "/", total)
print("Correct Answers:", correctAnswer)
print("Wrong Answers:", wrongAnswer)
print("_" * 30)

Post a Comment

Previous Post Next Post