why are you creating two topics for same question?
you can do this solution by using following steps :
- first open the file in read mode.
- readlines all lines of opened file using
file.readlines()
function . -
readlines()
function returned a list of all lines so to get one line at a time use for loop. - inside for loop split line at
" "
usingline.split(" ")
. - get the length of list returned by
split()
usinglen()
function.and this is result you want i.e. total number in one line. - create a variable with value 0.
- use for loop on list retuned by
line.split(" ")
- now add all numbers returned by for loop using variable created before.
you can find all the above explaination as code on the bellow link .to see the code just click on the blur text.
http://forum.freecodecamp.org/t/help-simple-python-code-needed/351725/2