If you have any questions, comments or issues with this project please post them here!
Hi, I’m struggling with Day48. The code isn’t failing but it’s also not adding to my file. Any help please?
while True:
name = input ("Input your initials: ")
score = input ("Enter your high score: ")
again = input (“add another? y/n? “)
if again == “y”:
continue
else:
break
f = open(“HighScore.”, “a+”)
f.write(f”{name} {score}\n”)
f.close()
As it stands you’re only writing the last entry to the files as you only get the the file writing code when the user breaks the loop and at that point the only name and score are the most recent.
Try
name = input ("Input your initials: ")
score = input ("Enter your high score: ")
f = open("HighScore.", "a+")
f.write(f"{name} {score}\n")
f.close()
again = input ("add another? y/n? ")
if again == "y":
continue
else:
break
And by moving the file writing code into the loop it’ll save after each one
2 Likes
Amazing - thank you!