this is the question:
The game() function in a program lets a user play a game and returns the score as an integer. You need to read a file"hiscore.txt" which is either blank or contains the previous high score. You need to write a program to update the high score whenever someone breaks the high score.
This is the code i have typed:
file=open("hiscore.txt","r")
c=file.read()
score=int(c)
file.close()
new_score=int(input("Enter ur new score"))
if score<new_score:
file=open("hiscore","w")
file.write(c)
The error is given below:
Traceback (most recent call last):
File "d:\python\blah.py", line 3, in <module>
score=int(c)
ValueError: invalid literal for int() with base 10: ''
What I have tried:
This is the code i have typed:
<pre lang="Python">
file=open("hiscore.txt","r")
c=file.read()
score=int(c)
file.close()
new_score=int(input("Enter ur new score"))
if score<new_score:
file=open("hiscore","w")
file.write(c)