Page 243 - Computer Science V2.0 Class 11
P. 243
# Function to display questions, get user input, and calculate the score
def score(quizQuestions):
userScore = 0
for ques in quizQuestions:
print(ques)
ans = input("Your answer: ")
if ans.lower() == questionsAndAnswers[ques].lower():
print("Correct!\n")
userScore += 1
else:
print("Wrong! The correct answer is questionsAndAnswers[ques]")
return userScore
# Function to display remarks based on the score
def remark(score):
if score == 5:
return "Outstanding"
elif score == 4:
return "Excellent"
elif score == 3:
return "Good"
elif score == 2:
return "Read more to score more"
elif score == 1:
return "Needs to take interest"
elif score == 0:
return "General knowledge will always help you. Take it seriously."
print("Welcome to the GK Quiz!\n")
# Create a quiz with five random questions
quizQuestions = createQuiz()
# Get user input, calculate score, and display remarks
userScore = score(quizQuestions)
print("Your final score:", userScore)
print(remark(userScore))
Answers
Multiple Choice Questions
1. (a) 2. (b) 3. (c) 4. (b) 5. (a) 6. (c) 7. (d) 8. (b) 9. (a)
10. (b) 11. (b) 12. (a) 13. (c)
True or False
1. (F) 2. (T) 3. (F) 4. (F) 5. (F) 6. (T) 7. (T) 8. (F) 9. (F)
10. (T) 11. (F) 12. (F)
Fill in the blanks
1. modular 2. def 3. None 4. function
5. Built-in Functions 6. : 7. arguments 8. void
Introduction to Functions 229

