Question: This is the assignment using PYTHON: Design and implement a quiz program based on States & Capitals. Your program should ask a fixed number of
This is the assignment using PYTHON: Design and implement a quiz program based on States & Capitals. Your program should ask a fixed number of questions and output the number of correct answers. The program must read questions and answer information from a file. For example, a .txt doc would contain the state and its capital on each line
This is my code:
def Question(Statecapitals): totalscore=0 print("States and Capital quiz: 5 questions 5 Marks ") print("What is the capital of ",states[1]) totalscore=calculatescore(states,scapitals,1,totalscore) print("What is the capital of "+states[2]) totalscore=calculatescore(states,scapitals,2,totalscore) print("What is the capital of "+states[0]) totalscore=calculatescore(states,scapitals,0,totalscore) print("What is the capital of "+states[3]) totalscore=calculatescore(states,scapitals,3,totalscore) print("What is the capital of "+states[4]) totalscore=calculatescore(states,scapitals,4,totalscore)
print("Your Total score is:") def calculatescore(states,scapitals,i,totalscore): useranswer=input().strip().upper() canswer=scapitals[states[i]].strip().upper()
if(canswer==useranswer): return totalscore+1 else: return totalscore def readFromFile(): c={} with open("capitalquiz.docx","r") as fp: alllines=fp.readlines()
count=1 for i in range(len(allines)-1): line=allallines[0].strip().split(":") line[0]=line[0][1:] cline[line[0]]=line[1] else: line=alllines[i].lstrip().split(":") c[line[0]]=line[1] askQuestions(d) readFromFile()
This is my error Traceback (most recent call last): File "C:/2021 python class/quiz.py", line 40, in
Help would be greatly appreciate !!!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
