Skip to content
Case Study-based Questions · Q2

Q.Participating in a quiz can be fun as it provides a competitive element. Some educational institutes use it as a tool to measure knowledge level, abilities and/or skills of their pupils either on a general level or in a specific field of study. Identify and analyse popular quiz shows and write a Python program to create a quiz that should also contain the following functionalities besides the one identified by you as a result of your analysis.
• Create an administrative user ID and password to categorically add, modify, delete a question
• Register the student before allowing her or him to play a quiz
• Allow selection of category based on subject area
• Display questions as per the chosen category
• Keep the score as the participant plays
• Display the final score

Rajasthan RbseTextbookSubjective· 5mImportance★★★★★est
63% · 19/30 Questions
✓ Free question

Two dictionaries carry the whole system — questions grouped by category and students with scores; admin credentials gate the add/modify/delete functions, and the play loop shows options, checks each answer and totals the score.

The idea. Analysing popular quiz shows (KBC-style ladders, rapid-fire rounds) yields the common core this program implements: a question bank organised by category, controlled admin maintenance of that bank, player registration, and transparent scoring shown at the end. Each question is [text, options-tuple, correct-option-number] — the options are a tuple (they never change one by one), while the question list itself is mutable so the admin can add, modify and delete.

Program:

ADMIN_ID = 'admin'
ADMIN_PW = 'quiz@123'

# questions[category] = list of [question_text, (options), correct_option_number]
questions = {
    'Science': [
        ['Which gas do plants absorb during photosynthesis?',
         ('Oxygen', 'Carbon dioxide', 'Nitrogen', 'Hydrogen'), 2],
    ],
    'Computer': [
        ['Which Python data type is immutable?',
         ('list', 'dictionary', 'tuple', 'set'), 3],
    ],
}
students = {}          # (roll, name) -> final score

def admin_login():
    uid = input("Admin ID: ")
    pw = input("Password: ")
    return uid == ADMIN_ID and pw == ADMIN_PW

def add_question():
    cat = input("Category: ")
    text = input("Question text: ")
    opts = ()
    for i in range(1, 5):
        opts = opts + (input("Option " + str(i) + ": "),)
    correct = int(input("Correct option number (1-4): "))
    if cat not in questions:
        questions[cat] = []
    questions[cat].append([text, opts, correct])
    print("Question added to category", cat)

def modify_question():
    cat = input("Category: ")
    for i in range(len(questions[cat])):
        print(i + 1, "-", questions[cat][i][0])
    n = int(input("Question number to modify: "))
    questions[cat][n - 1][0] = input("New question text: ")
    print("Question updated")

def delete_question():
    cat = input("Category: ")
    for i in range(len(questions[cat])):
        print(i + 1, "-", questions[cat][i][0])
    n = int(input("Question number to delete: "))
    removed = questions[cat].pop(n - 1)
    print("Deleted:", removed[0])

def register_student():
    name = input("Student name: ")
    roll = input("Roll number: ")
    students[(roll, name)] = 0
    print(name, "registered successfully")
    return (roll, name)

def play_quiz(student):
    print("Available categories:", ", ".join(questions.keys()))
    cat = input("Choose a category: ")
    if cat not in questions:
        print("No such category")
        return
    score = 0
    for text, opts, correct in questions[cat]:
        print()
        print(text)
        for i in range(len(opts)):
            print("  ", i + 1, ")", opts[i])
        ans = int(input("Your answer (1-4): "))
        if ans == correct:
            print("Correct!")
            score = score + 1
        else:
            print("Wrong. Correct answer:", opts[correct - 1])
    students[student] = score
    print()
    print("Final score of", student[1], ":", score, "out of", len(questions[cat]))

while True:
    print()
    print("1.Admin  2.Play quiz  3.Exit")
    choice = input("Enter choice: ")
    if choice == '1':
        if admin_login():
            print("a.Add question  b.Modify question  c.Delete question")
            sub = input("Enter option: ")
            if sub == 'a':
                add_question()
            elif sub == 'b':
                modify_question()
            elif sub == 'c':
                delete_question()
        else:
            print("Invalid admin credentials")
    elif choice == '2':
        student = register_student()
        play_quiz(student)
    elif choice == '3':
        print("Goodbye!")
        break

Sample session (admin adds a question, then a student plays):

1.Admin  2.Play quiz  3.Exit
Enter choice: 1
Admin ID: admin
Password: quiz@123
a.Add question  b.Modify question  c.Delete question
Enter option: a
Category: Science
Question text: Which vitamin does our skin make in sunlight?
Option 1: Vitamin A
Option 2: Vitamin B12
Option 3: Vitamin C
Option 4: Vitamin D
Correct option number (1-4): 4
Question added to category Science

1.Admin  2.Play quiz  3.Exit
Enter choice: 2
Student name: Riya
Roll number: 11
Riya registered successfully
Available categories: Science, Computer
Choose a category: Science

Which gas do plants absorb during photosynthesis?
   1 ) Oxygen
   2 ) Carbon dioxide
   3 ) Nitrogen
   4 ) Hydrogen
Your answer (1-4): 1
Wrong. Correct answer: Carbon dioxide

Which vitamin does our skin make in sunlight?
   1 ) Vitamin A
   2 ) Vitamin B12
   3 ) Vitamin C
   4 ) Vitamin D
Your answer (1-4): 4
Correct!

Final score of Riya : 1 out of 2

1.Admin  2.Play quiz  3.Exit
Enter choice: 3
Goodbye!

Key lines:

  • admin_login() compares the entered ID and password against the stored credentials; only then is the add/modify/delete submenu offered.
  • questions.setdefault-style guard (if cat not in questions: questions[cat] = []) lets the admin create a brand-new category simply by adding a question to it.
  • students[(roll, name)] = 0 registers the player before the quiz starts, as required, and the final score is written back to that entry.
  • The play loop prints each option numbered, reads the choice, and either increments the score or reveals the correct answer — so the score is kept as the participant plays.
Tip

Extensions identified from real quiz shows fit naturally here: a per-question timer (time.time() before/after the input), difficulty levels as another dictionary layer, or negative marking by subtracting on a wrong answer.

✓Final answer

The program provides admin-authenticated question management, student registration, category-wise question display and live scoring; in the sample run Riya scores 1 out of 2 in Science.

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.