def add(a,b): # calculating the sum sum=a+b #opening the file in an append mode file = open('output.txt',"a") file.write(f'Sum of {a} and {b} is {sum}\n') #at last i close the file file.close() #call the function add(5,7) add(2,6)