with open("c:\\Users\\XMBC\\Documents\\lesson13-1\\sales_list.txt",'r',encoding='utf-8') as f1: a=f1.readlines() j=[] for i in a: s=i.split() #print(s[1:]) q=0 for d in s[1:]: q=q+int(d) j.append(s[0]+str(q)+'\n') with open(r"C:\Users\XMBC\Desktop\blackery.txt",'w',encoding='utf-8') as m: m.writelines(j)