我正在将名称和分数添加到文件中,并试图弄清楚如何在将数据写入文件后开始换行。到目前为止,这是我的代码,但是当我在文件中继续时,所有变量都在同一行上:
print "That's the game folks! You finished with a final score of...", points, 'points! Good game, you made the high score list! What is your name?'
name = raw_input()
w = open('Highscores', 'a')
w.write(name)
w.write(str(points))
w.close()
在 unix 上使用 \n
换行,在 Windows 上使用 \r\n
。只需添加到字符串的末尾即可。
w.write(str(points) + '\n')
或
print "That's the game folks! You finished with a final score of...", points, 'points! Good game, you made the high score list! What is your name?\n'
我是一名优秀的程序员,十分优秀!