Question: Please help make a python programming def showResult(score) : if score 2 and score
Please help make a python programming
def showResult(score) :
if score <= 2 : # final score = 0,1,2
print("Better luck next time.")
elif score>2 and score<=4 : #final score= 3,4
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
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
