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 | General knowledge will always help you. Take it seriously. |
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Keep the five question–answer pairs in a list, randomise their order with random.shuffle(), count correct responses in the user-defined function score(), and let remark(scorevalue) translate the final score into the table's message.
The idea. This task combines three things the chapter teaches: the random module (for the random display order), and two user-defined functions that split the work cleanly — score() computes, remark() presents. Indexing a list by the score is a neat way to store the remarks table: remarks[0] is the message for 0, … remarks[5] for 5.
import random
quiz = [["What is the capital of India?", "new delhi"],
["Which planet is called the Red Planet?", "mars"],
["What is the currency of Japan?", "yen"],
["Which is the largest ocean in the world?", "pacific"],
["Which is the national bird of India?", "peacock"]]
def score(responses):
"""Return the number of correct responses."""
total = 0
for given, correct in responses:
if given.strip().lower() == correct:
total = total + 1
return total
def remark(scorevalue):
"""Display the remark for the final score (0..5)."""
remarks = ["General knowledge will always help you. Take it seriously.",
"Needs to take interest",
"Read more to score more",
"Good",
"Excellent",
"Outstanding"]
print("Your score:", scorevalue, "out of 5")
print("Remark:", remarks[scorevalue])
random.shuffle(quiz) # questions come up in random order
responses = []
for question, answer in quiz:
reply = input(question + " ")
responses.append([reply, answer])
remark(score(responses))
Key lines
random.shuffle(quiz)— reorders the list in place, so every run asks the questions in a different order.score()compares each response (lower-cased, stripped) with the stored answer and returns the count — a pure computation. …
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.