I'm stuck this code one day and half and Google is not helping. It sounds good to me but it is throwing errors.
The program runs through a quiz and finally collects a score as shown here:
Print ("This was the last question!") Print ("Your final score (score)) I know the score works but when I enter the players' names It then tries to run my highscore definition:
Diff The highest score (score, name): entry = (score, name) hs_data = open ('tops.dat', 'rb') highsc = Pickle.load (hs_data) hs_data.close () hs_data = open ('tops.dat ',' Ab ') highsc.append (entry) highsc.sort (reverse = true) highsc = highsc [: 5] pickle.dump (high cc, hs_data) hs_data.close () returns highsc But I get the same error every time: -
file "c: \" high escisi hi = pikel.load (hs_data) file "c: \ Python 31 \ library ", Line 1365, load encoding = encoding, users \ errors for errors Desktop \ py3e_source \ py3e_source \ trivia_challenge.py ", line 55 = errors) Klod () EOFError Plea Ase help.
You are opening an empty file, reaching pickles end Finds anything for unpickle , you can fix it by holding EOFError and setting the default value on hold. Something like this should work:
with open ('tops.dat', 'rb') hs_data: try: highsc = pickle.load (hs_data) Except EOFError: highsc = []
No comments:
Post a Comment