This question already has an answer here:
After answering the first question, the second question doesn't come up and the code just asks me to insert the answer again. Also how do I make the code seem robust enough that even if the user types other letters such as "g" and "h"the code wont crash. I'm doing a school project and would appreciate the help :)
print ('WELCOME TO THE MULTIPLE CHOICE TEST\n')
name = input('WHAT IS YOUR NAME? ')
print ('\nHI THERE ' + name + '! LET''S PLAY A GAME!\n')
print ('I will ask you 10 questions and give you four choices for each question.\n\nYou select which choice is the correct answer. Eg. A, B,C or D\n')
score = 0
score = int(score)
qn1 = ["What's color of sky?", "a)Red", "b)Blue", "c)White", "d)Black"]
def print_question(qn_num):
for st in qn_num:
print(st)
print_question(qn1)
while(True):
answer = input ("select answer: ")
if answer == 'b':
print ("good work")
score = score + 1
else:
print ("better luck next time")
score = score + 0
print("Your score is: " + str(score))
qn2 = ["The atom is made of?", "1)Protons and Quarks", "2)Protons, Neutrons and Electrons", "3)Neutrinos, Gamma Rays and Positrons", "4)Positrons, Neutrons and Electrons"]
def print_question(qn_num):
for st in qn_num:
print(st)
print_question(qn2)
Aucun commentaire:
Enregistrer un commentaire