Enter the sum of n numbers using file

n=int(raw_input('Enter the n for sum of n numbers: '))
f=open('integers.txt','w')
for count in range(n+1):
      f.write(str(count)+"\n")
f.close()

f=open('integers.txt','r')
sum=0
for l in f:
      l=l.strip()
      number=int(l)
      sum+=number
print 'The sum is',sum

No comments: