For the version Python2.6, it's preferred to use str.format()method:-
with open("Output.txt", "w") as text_file: text_file.write("Purchase Amount: {0}".format(TotalAmount))
If you are using Python2.7 and higher versions you can use {} instead of {0} which we have used in Python 2.6:-
with open("Output.txt", "w") as text_file: text_file.write("Purchase Amount: {}".format(TotalAmount))
If you are working with Python3.6 then you will have to use f-string which is introduced in Python3.6:-
with open("Output.txt", "w") as text_file:
print(f"Purchase Amount: {TotalAmount}", file=text_file)
To know more about this you can have a look at the following video tutorial:-
Learn more about Python from an expert. Enroll in our Python Course!