我已经编写了以下函数来记录随机数
def randomize(min, max, filename, entries):
filename = open("henlo.txt", "w")
for i in range(entries):
variable = random.randint(min, max)
filename.write(str(variable))
filename.close()
我的问题是制作一个读/写数字的函数。我需要把随机数写在单独的线上
下次格式化问题中的代码,使其可读。
试试这个,
def randomize(min_, max_, filename, entries):
with open(filename, "w") as fp:
fp.write("n".join(
(str(random.randint(min_, max_)) for _ in range(entries))
))