【问题标题】:Writing on a separate lines in a text file在文本文件的单独行上写入
【发布时间】:2023-04-05 11:33:02
【问题描述】:
import random

device = input("What device do you have? Phone or PC(laptop included). If other 
please specify ").upper()

make = ("")

model= ("")

verison = ("")

memory = ("")

if device == ("PHONE"):

 make = input ("what make of phone do you have? Iphone or Samsung or other").upper()
if make == ("IPHONE"):
    model == input("What model is your iPhone 6 or 7. If other plese spectify")

if device != ("PHONE") or ("PHONE") or (""):

  make =input("what make is your " + str(device)).upper()
  model = input("whats model is your " + str(device)).upper()
  verison = input("what verison is your " + str(device)).upper()
  memory = int(input("How much memory is in your " + str(device)))
  print(make, model, verison, memory,"GB")
  print(casenumber)
  f = open('technician.txt','a')
  f.write("**CASE NUMBER:{}** ** DEVICE: {}** **MAKE OF DEVICE: {}** **MODEL    OF DEVICE: {} **".format(casenumber,device,make,model,verison,memory))
f.write("/n")
f.close()

我想要做的是每次程序完成时在单独的行上写一个。但是 /n 不起作用。我运行了两次程序,它所做的只是写在文本文件的同一行:

案例编号:574927542749031461928599801595193290973875978 **设备:TABEL** 设备制造商:苹果 设备型号:IPAD **/n案例编号:207884437699822095837989343019189844675528960** ** 设备:平板电脑** 设备制造商:苹果 **设备型号:2 **/n

所有这些都在同一行。请帮忙

非常感谢,

罗里·伊斯特姆

【问题讨论】:

  • 换行符是“\n”而不是“/n”。注意反斜杠。
  • 感谢您的帮助:)

标签: python computer-science


【解决方案1】:

换行符是\n,而不是程序中使用的/n。使用此更新您的代码应该可以解决您所描述的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-02
    • 1970-01-01
    • 2016-03-08
    • 1970-01-01
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多