Question

Write a program that creates a GK quiz consisting of any five questions of your choice. The questions should be displayed randomly. Create a user defined function score() to calculate the score of the quiz and another user defined function remark (`scorevalue`) that accepts the final score to display remarks as follows:

Marks

Remarks

5

Outstanding

4

Excellent

3

Good

2

Read more to score more

1

Needs to take interest

0

Take it seriously.

✨ Free AI Tools for You

Powered by Chatterbot AI

Answer

Here's a Python program to create a GK quiz with five random questions. It includes user-defined functions for calculating the score and providing remarks based on the score.

import random

# Function to ask questions and return score
def score():
    questions = {
        "What is the capital of France?": "Paris",
        "In which year did World War I begin?": "1914",
        "What is the largest planet in our solar system?": "Jupiter",
        "Who wrote 'Romeo and Juliet'?": "Shakespeare",
        "What is the chemical symbol for water?": "H2O"
    }

    # Shuffle and get the first 5 questions
    selected_questions = random.sample(list(questions.items()), 5)
    correct_answers = 0

    for question, answer in selected_questions:
        user_answer = input(question + " ")
        if user_answer.strip().lower() == answer.lower():
            correct_answers += 1

    return correct_answers

# Function to provide remarks based on score
def remark(scorevalue):
    if scorevalue == 5:
        return "Outstanding"
    elif scorevalue == 4:
        return "Excellent"
    elif scorevalue == 3:
        return "Good"
    elif scorevalue == 2:
        return "Read more to score more"
    elif scorevalue == 1:
        return "Needs to take interest"
    else:
        return "Take it seriously."

# Main program execution
final_score = score()
print(f"Your score is: {final_score}/5")
print(remark(final_score))

How It Works:

  1. score() Function: This function contains a dictionary of five questions and their correct answers. It selects 5 random questions, prompts the user for answers, and calculates the number of correct responses.

  2. remark(scorevalue) Function: Based on the input score, it returns an appropriate message.

  3. Main Execution: The program calculates the score and prints both the score and the remark.

Key Points:

  • Randomization: The random.sample function ensures that different questions are asked each time the quiz is taken.

  • Input Matching: User inputs are compared to the correct answers in a case-insensitive manner.

  • Structured Output: The score and corresponding remarks are displayed at the end.


Was this helpful?

India's 1st AI Doubt Solver for CBSE, JEE, and NEET

Ask a Question for Free

and then it's just ₹212 a month

Learn how Chatterbot AI can help you succeed

Cover Image of the article Computer Science Class 11 CBSE - The Ultimate Guide with Notes, Solutions and AI

Computer Science Class 11 CBSE - The Ultimate Guide with Notes, Solutions and AI

This ultimate guide for CBSE Computer Science class 11 has detailed notes, NCERT solutions, cheat sheets, and our free AI-powered doubt-solving assistant, Chatterbot AI.

Cover Image of the article JEE Advanced 2024 Exam Date Announced: Complete Guide to Eligibility, Syllabus, and Preparation Tips

JEE Advanced 2024 Exam Date Announced: Complete Guide to Eligibility, Syllabus, and Preparation Tips

JEE Advanced 2024 on May 26! Get exam schedule, syllabus, prep tips & more in this guide. Ace India's top engineering test with topper strategies.

Cover Image of the article How to Crack NEET: The Ultimate Blueprint to Outsmart the Exam and Unlock Your Medical Dreams

How to Crack NEET: The Ultimate Blueprint to Outsmart the Exam and Unlock Your Medical Dreams

Ace NEET with expert strategies: Discover effective exam strategies, time management, core concepts mastery, problem-solving techniques, revision tips, and AI-assisted doubt clearing with Chatterbot AI.

Cover Image of the article How to Crack IIT: Smart Self-Study Strategies and AI Tools for Success

How to Crack IIT: Smart Self-Study Strategies and AI Tools for Success

Ace IIT JEE in 6 months without coaching. Discover expert self-study strategies for Physics, Chemistry, and Math. Master time management, mock tests, and leverage AI tools like Chatterbot AI for personalized doubt-solving.