Question 15 of 17advanced🔧 ApplyLong Answer5 marks

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 5: Outstanding Marks 4: Excellent Marks 3: Good Marks 2: Read more to score more Marks 1: Needs to take interest Marks 0: General knowledge will always help you. Take it seriously.

Correct Answer

To create the GK quiz program, we first import the random module to facilitate the random display of questions. We define two lists: one for the questions and another for the corresponding answers. The program logic is divided into two distinct user defined functions as required by the question.

The first function, score(), is defined to calculate the score. Inside this function, we use a list of indices which is shuffled using random.shuffle() to display questions randomly. The function iterates through the questions, accepts user input, and checks it against the answer list. For every correct answer, the score counter increments by 1. This function returns the final calculated score.

The second function, remark(scorevalue), accepts the score returned by the previous function. It uses conditional statements (if-elif-else) to check the score against the given criteria. Depending on the score value (0 to 5), it prints the specific remark mapped to that score, such as 'Outstanding' for 5 marks or 'General knowledge will always help you...' for 0 marks.

Finally, the main program executes these functions sequentially. The score() function is called to conduct the quiz, and its result is passed as an argument to the remark() function to display the feedback.

python import random

Lists storing questions and answers

questions = [ "What is the capital of India?", "Which is the largest planet?", "What is the formula of water?", "Which is the national bird of India?", "Which planet is known as the Red Planet?" ] answers = [ "New Delhi", "Jupiter", "H2O", "Peacock", "Mars" ]

User defined function to calculate score

def score(): s = 0 # indices to shuffle questions randomly indices = [0, 1, 2, 3, 4] random.shuffle(indices)

for i in indices:
    print("\nQ:", questions[i])
    user_ans = input("Your Answer: ")
    # Check if answer matches
    if user_ans == answers[i]:
        s = s + 1
return s

User defined function to display remarks

def remark(scorevalue): if scorevalue == 5: print("Outstanding") elif scorevalue == 4: print("Excellent") elif scorevalue == 3: print("Good") elif scorevalue == 2: print("Read more to score more") elif scorevalue == 1: print("Needs to take interest") else: print("General knowledge will always help you. Take it seriously.")

Main program execution

final_score = score() print("\nYour Score:", final_score) remark(final_score)

Exercise: SUGGESTED LAB. EXERCISES | Q: 8 | (Page 31)
For More Understanding

Explanation

The answer constructs a Python program as requested by the textbook context. It utilizes the 'random' module mentioned in the context (specifically hinted at in the 'ABC School' question for automation) to shuffle the quiz questions. It defines the two required user-defined functions: score() to handle the quiz logic and return the marks, and remark(scorevalue) to print specific feedback based on the score table provided in the question. The code includes comments as per the 'Activity-Based Questions' guidelines in the context.

Solution Steps

  1. Step 1: Import the random module and define lists for questions and answers.

  2. Step 2: Define the function score() to shuffle questions, take inputs, and return the total score.

  3. Step 3: Define the function remark(scorevalue) to check the score against the given table and print the corresponding remark.

  4. Step 4: Call the score() function to get the result and pass that result to the remark() function.