(1) Define a function for summing data. The function name is addList (). List=[1,3,8,9,5,6] (3) Read data from List, and use addlist() function to sum. (4) Save the calculation result of summation in the file T1.txt.
Fp =open(' ceshi1.txt ',mode= 'w',encoding= 'utf-8') fp.write(' put elephant in ') fp.close() 2: file read operation: Open fp=open(' 888 ',mode= "r",encoding= 'utf-8') read res=fp.read() print(res) close fp.
Def addList (n): sum=0 for I in n: Fp = open('t1.txt',mode='w+') return sum List=[1,3,8,9,5,6] fp.write(str(jieguo)) fp.close()