天天看點

Python 将數字寫入到一個文本檔案

import random
with open("2.txt","w") as f:
  for i in range(5):
    number=random.randint(1,50)
    text=f.write(str(number)+"\n")
    print(text)
f.close()