Hey everyone, I need help with a Python issue. This is what I have so far:
scores = []
choice = None
while choice != "0":
print \
"""
High Scores Keeper
0 - Quit
1 - List Scores
2 - Add a Score
"""
choice = raw_input("Choice: ")
print
if choice == "0":
print "Good-bye."
elif choice == "1":
print "High Scores\n"
print "NAME\tSCORE"
for entry in scores:
score, name = entry
print name, "\t", score
elif choice == "2":
name = raw_input("What is the player's name?: ")
score = int(raw_input("What score did the player get?: "))
entry = (score, name)
scores.append(entry)
scores.sort()
scores.reverse()
scores = scores[:5]
else:
print "Sorry, but", choice, "isn't a valid choice."
raw_input("\n\nPress the enter key to exit.")
I need to set it up so that when the program loads and saves the high scores on the program by using a text file. For example, when the user first launches the program, it should try and load the scores from the text file. I need to also set it so if it doesn't exist, the program should use exception handling to avoid the program ending, along with stating that the file could not be loaded.
Also, when the program gets closed down when the user is finished, I need it to write the high scores onto the text file. I need it to also have exception handling just like mentioned above.
Can someone please help me?