python output to text file

C++
file = open(“testfile.txt”,”w”) 
 
file.write(“Hello World”) 
file.write(“This is our new text file”) 
file.write(“and this is another line.”) 
file.write(“Why? Because we can.”) 
 
file.close() file1 = open("MyFile.txt","w+") 

file1.readline()

fil1.write("string")

file1.close()f=open("Diabetes.txt",'r')
f.read()price = 33.3
with open("Output.txt", "w") as text_file:
    text_file.write("Purchase Amount: %s price %f" % (TotalAmount, price))$ python my_program.py > output.txt
Source

Also in C++: