Question: this function takes final score and prints corresponding message def showResult(score) : if score print(Better luck next time.) elif score>2 and score print(Not bad. Try
this function takes final score and prints corresponding message
def showResult(score) :
if score
print("Better luck next time.")
elif score>2 and score
print("Not bad. Try again soon!")
else : #final score = 5
print("Awesome! You rock!")
print("================================")
#this function takes answer list, index and submitted answer
# and returns 1 if it is correct, else returns 0
#we convert both to lower case so that answer will be correct regardless of case
def check(ans, index, userAns) :
if ans[index].lower() == userAns.lower() :
return 1
else :
return 0
#Main program
#define questions
q1 = "What is the Capital of America ?"
q2 = "What is the Capital of Japan?"
q3 = "What is the Capital of China ?"
q4 = "What is the Capital of Russia?"
q5 = "What is the Capital of Korea ?"
#store questions in a list
q = [q1,q2,q3,q4,q5]
#store answers
ans = ["Washington, dc,", "Tokyo", "Beijin", "Moscow", "Seoul"]
#create variable to store score
finalScore = 0
print("Quiz starting...")
for i in range(5) : #run 5 times
userAns = input(q[i]) #store answer
if check(ans,i,userAns) ==1 :
print("Correct")
finalScore += 1 #update score
else :
print("Incorrect")
showResult(finalScore) #show final Message
Instructions Modify your quiz from the last assignment as follows: For each question, instead of keeping score, continue asking the same question until the user guesses the correct question or types "skip" (allow both upper and lower case) If the user guesses correctly, issue a . If the user guesses incorrectly, issue a If the user types "skip", continue to the correct" message, sorry, try again" message next question. When all questions have been asked/answered/skipped, ask the user if they would like to play again. If so, start the quiz over again from the beginning Otherwise, print out a "Thank you for playing" type of message. Note: You do not need to keep score in this quiz
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
