Python 发送到“的每个号码的换行符”;stuff.txt“;

Python 发送到“的每个号码的换行符”;stuff.txt“;,python,line-breaks,Python,Line Breaks,我试着为我发送到“stuff.txt”的每一个数字做一次换行 这是我的密码 import dice # dice is a module i used d = 1 stuff = open("stuff.txt", "a") while d <= 100: print(d) d = d + 1 stuff.write(str(dice.roll_dice(4) )) print("sent a rando

我试着为我发送到“stuff.txt”的每一个数字做一次换行

这是我的密码

import dice # dice is a module i used

d = 1
stuff = open("stuff.txt", "a")
while d <= 100:
    print(d)
    d = d + 1
    stuff.write(str(dice.roll_dice(4)  ))
    print("sent a random number from 1-4 to stuff.txt")
stuff.close()

当我运行代码时,我得到100个骰子,但所有数字都在同一行。我想做的是用换行符把这些数字放在不同的行上。我想把数字变成:

1
2
3
只需在每个字符后面添加
\n
(换行符),而不是123。即:

stuff.write(str(dice.roll_dice(4)  )+"\n")

投票以@muw you's welcome的复制品结束。
stuff.write(str(dice.roll_dice(4)  )+"\n")