count = 100
start = input("Welcome to Reign of Terror \n 1-Start Game 2-Highscores")
if start == "2":
hisc = open("highscore.txt", "a+")
hisc.write(count,"\n")
When I run the code and choose 2, I get the error
TypeError: write() takes exactly one argument (2 given)
Write takes one string, not two.
if start == "2":
with open("highscore.txt", "a+") as hisc:
hisc.write("{}\n".format(count))
Also, use with so your file gets closed after writing.
@kabanus answered this, thanks!
It says exactly what the error is. Pass a single argument
hisc.write(str(count)+"\n")will work." – kabanus
So this is the correct code:
hisc.write(str(count)+"\n")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With