-2

I have done a program with 4 functions, now I have to add the results produced by the functions into a text file from python. How can I do that?

1 Answers1

0

open a text file where you want to save and put it in the write mode

def func1(a, b):
    return a+b
def func2(a, b):
    return a-b
def func3(a, b):
    return a*b
def func4(a, b):
    return a/b

txt_write = open('file_name', 'w+')
txt_write.writelines(func1(2,6))
txt_write.writelines(func2(7,1))
txt_write.writelines(func3(6,3))
txt_write.writelines(func4(9,3))
txt_write.close()

use writelines to write in the text file. Don't forget to close the file.

Fahim Ahmed
  • 141
  • 11