Reputation:
Ok, well, i am trying to make a little program that asks you to enter a file name and it will create the file with the name you wanted. in that File it will display the adult price and the children price on two different lines. Anyone?
packagename = input("Enter package name:")
packagepriceadult = input ("Enter package price per adult:")
packagepricechild = input("Enter package price per child:")
a = open ("output.txt", "a")
a.write (packagename),"\n"
a.write (packagepriceadult)
a.write (packagepricechild)
Upvotes: 0
Views: 1096
Reputation: 5207
if you're using python 2.x you can also do like I've done here:
outlist = [packagename, packagepriceadult, packagepricechild]
a.write('\n'.join(outlist))
Upvotes: 0
Reputation: 2752
Another option available in python 2.x is to redirect the print statement to the file
print >>a, packagename
print >>a, packagepriceadult
print >>a, packagepricechild
See this post more info - slippens's blog
Upvotes: 1
Reputation: 23316
Simply write the linebreak to the file, for example:
a.write(packagename)
a.write("\n")
a.write(packagepriceadult)
a.write("\n")
a.write(packagepricechild)
Upvotes: 0