有人能教我如何将第二个打印值写入txt文件吗
while True:
num = int(input(""" Enter Number: """))
temp = num
numb = temp
zar = 1
print("Develped by Umar Mushtaq")
for _ in range(10):
print(numb, "X", zar, "=", num)
num += numb
zar+= 1
print("Press Ctrl+C To Exit")
您可以在txt
文件中这样写:
f = open("filename.txt", "w")
f.write("Whatever you want to write...!!!!")
f.close()
这是覆盖文件。若要追加到现有文件中,可以在参数中使用a
而不是w
。
"a" - Append - will append to the end of the file
"w" - Write - will overwrite any existing content
但它给出了一个错误:。TypeError:write((只接受一个参数(给定5个(
with open("write.txt", "w") as f:
while True:
num = int(input(""" Enter Number: """))
temp = num
numb = temp
zar = 1
print("Develped by Umar Mushtaq")
for _ in range(10):
print(numb, "X", zar, "=", num)
f.write(numb, "X", zar, "=", num)
num+= numb
zar+= 1
print("Press Ctrl+C To Exit")