Python Homework Help! Simple Code Needed

why are you creating two topics for same question?
you can do this solution by using following steps :

  1. first open the file in read mode.
  2. readlines all lines of opened file using file.readlines() function .
  3. readlines() function returned a list of all lines so to get one line at a time use for loop.
  4. inside for loop split line at " " using line.split(" ").
  5. get the length of list returned by split() using len() function.and this is result you want i.e. total number in one line.
  6. create a variable with value 0.
  7. use for loop on list retuned by line.split(" ")
  8. 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

1 Like