Computer Science, asked by rishixpress, 9 months ago

A Python Program to make a multiple choice quiz using Dictionary​

Answers

Answered by dheeraj4290
0

Answer:

I'm making a quiz of yes/no questions where answering yes/no depending on the question rewards a different amount of points, which after each question will be added to a total and displayed at the end.

However, there are around 50 questions in the quiz, and this would mean a mountain of if/else statements. Is there a way I can use a dictionary and a loop or something similar to significantly reduce the length of the program?

edit This repeated many times is what I'm trying to avoid. I'm thinking of adding a variable i and adding 1 to it after each question, and looking up the index of the next question.

print "The following are y/n questions."

total = 0

q1 = raw_input("Do you exercise daily? ")

if q1 == "y":

total += 1

else:

total = total

print total

Similar questions