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 readFromFile() File "C:/2021 python class/quiz.py", line 28, in readFromFile alllines=fp.readlines() File "C:\Users\ksoll\AppData\Local\Programs\Python\Python39\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 591: character maps to

Help would be greatly appreciate !!!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!