From cb63d7f7b528218d80521c8919bebd87c193a53b Mon Sep 17 00:00:00 2001 From: Anushka2726 Date: Thu, 23 Oct 2025 15:51:54 +0530 Subject: [PATCH] added quiz --- .../Programs/Python/quiz/README.md | 84 +++++++++++++++++++ .../Programs/Python/quiz/quiz.py | 51 +++++++++++ 2 files changed, 135 insertions(+) create mode 100644 Domains/CompetitiveProgramming/Programs/Python/quiz/README.md create mode 100644 Domains/CompetitiveProgramming/Programs/Python/quiz/quiz.py diff --git a/Domains/CompetitiveProgramming/Programs/Python/quiz/README.md b/Domains/CompetitiveProgramming/Programs/Python/quiz/README.md new file mode 100644 index 00000000..af04329a --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/Python/quiz/README.md @@ -0,0 +1,84 @@ +contributer Anushka2726 +πŸ“‹ Description + +This is a Simple Quiz App built using Python. +It asks the user multiple-choice questions, takes their input (A/B/C/D), and calculates the final score at the end. +It’s a perfect beginner-friendly project to practice loops, conditionals, and lists/dictionaries in Python. + +πŸš€ Features + +βœ… Multiple-choice questions +βœ… Instant feedback (Correct/Wrong) +βœ… Score counter +βœ… Easy to modify or expand with new questions + +🧩 How It Works + +The quiz questions are stored in a list of dictionaries. + +Each question dictionary includes: + +"question" β†’ the question text + +"options" β†’ list of answer choices + +"answer" β†’ correct option (A, B, C, or D) + +The program displays one question at a time. + +The user inputs their answer. + +The app checks if the answer is correct and keeps track of the score. + +At the end, it shows your total score. + +πŸ–₯️ Example Output +1. What is the capital of France? +A. Berlin +B. Madrid +C. Paris +D. Rome +Enter your answer (A/B/C/D): c +βœ… Correct! + +2. Which language is used for web apps? +A. Python +B. JavaScript +C. HTML +D. All of the above +Enter your answer (A/B/C/D): d +βœ… Correct! + +🎯 You got 2 out of 2 correct! + +🧰 Requirements + +Python 3.x +(No external libraries required) + +▢️ How to Run + +Copy the code into a file named quiz_app.py + +Open a terminal or command prompt. + +Run the script: + +python quiz_app.py + + +Answer each question by typing A, B, C, or D, and press Enter. + +🧠 Future Improvements + +Add more questions from a text or JSON file. + +Randomize question order using random.shuffle(). + +Add timer functionality. + +Create a GUI version using tkinter. + +Save user scores to a file. + + diff --git a/Domains/CompetitiveProgramming/Programs/Python/quiz/quiz.py b/Domains/CompetitiveProgramming/Programs/Python/quiz/quiz.py new file mode 100644 index 00000000..e7c9d746 --- /dev/null +++ b/Domains/CompetitiveProgramming/Programs/Python/quiz/quiz.py @@ -0,0 +1,51 @@ +# Simple Quiz App in Python + +def run_quiz(questions): + score = 0 + for q in questions: + print("\n" + q["question"]) + for option in q["options"]: + print(option) + answer = input("Enter your answer (A/B/C/D): ").upper() + if answer == q["answer"]: + print("βœ… Correct!") + score += 1 + else: + print(f"❌ Wrong! Correct answer is {q['answer']}") + print("\n🎯 You got", score, "out of", len(questions), "correct!") + + +# List of questions +questions = [ + { + "question": "1. What is the capital of France?", + "options": ["A. Berlin", "B. Madrid", "C. Paris", "D. Rome"], + "answer": "C" + }, + { + "question": "2. Which language is used for web apps?", + "options": ["A. Python", "B. JavaScript", "C. HTML", "D. All of the above"], + "answer": "D" + }, + { + "question": "3. What is 5 + 7?", + "options": ["A. 10", "B. 12", "C. 14", "D. 15"], + "answer": "B" + }, + { + "question": "4. Who developed Python?", + "options": ["A. Guido van Rossum", "B. Elon Musk", "C. Bill Gates", "D. Mark Zuckerberg"], + "answer": "A" + }, + { + "question": "5. What does HTML stand for?", + "options": ["A. Hyper Trainer Marking Language", + "B. Hyper Text Markup Language", + "C. Hyper Text Marketing Language", + "D. None of these"], + "answer": "B" + } +] + +# Run the quiz +run_quiz(questions)