Reputation: 77
Every time the game switches to "gameover-mode" a line should be added to the scoreboard.csv file. I wrote a funtion to do this, but I keep getting this error message:
Traceback (most recent call last):
File "C:\Users\Timo\PycharmProjects\2DFlugzeugspiel\main.py", line 208, in <module>
scoreboard_write()
File "C:\Users\Timo\PycharmProjects\2DFlugzeugspiel\main.py", line 93, in scoreboard_write
writer.writerow(current_player, score, date)
TypeError: writer.writerow() takes exactly one argument (3 given)
Otherwise the program works perfectly fine and there are no errors.
def scoreboard_write():
from datetime import date # Import module for date
today = date.today()
date = today.strftime("%d/%m/%Y")
with open ("scoreboard.csv", "a", newline="") as scoreboard: # Open scoreboard.csv
writer = csv.writer(scoreboard)
writer.writerow(current_player, score, date)
...
# Gameover screen
while running == 3:
scoreboard_write()
gameover = False
The variable current_player
is a string, the score
is an integer.
Upvotes: 0
Views: 3171
Reputation: 102902
Change
writer.writerow(current_player, score, date)
to
writer.writerow([current_player, score, date])
and you should be all set. From the csv.Writer
docs, "A row must be an iterable of strings or numbers for Writer
objects".
Upvotes: 2