0

Hi I am a beginner and very new to python. I am just trying to understand how to print the total sum of numbers in a file.

I have used the code to just open and read the file,

f = open("example.txt") print(f.read())

but I was wondering if anyone knew a way to sum all the numbers within the file and print the end result (I am using python 2.7). Thank you for your time.

Jasmine W
  • 1
  • 1
  • file ontains only numbers ? check these : [http://stackoverflow.com/questions/16533821/sum-of-all-numbers-in-a-file](http://stackoverflow.com/questions/16533821/sum-of-all-numbers-in-a-file) [http://stackoverflow.com/questions/14791256/python-how-to-sum-numbers-from-text-file](http://stackoverflow.com/questions/14791256/python-how-to-sum-numbers-from-text-file) – Vaibhav Jul 20 '16 at 18:30
  • Read file -> tokenize contents -> parse each token as a number -> sum. When approaching a problem like this, think about each individual problem that you need to solve. This is actually several smaller problems; each of which is only minimally related to each other. – Carcigenicate Jul 20 '16 at 18:52

0 Answers0