• anonymous
n = int(input ("enter the number input; ")) sumN = 0 for nCount in range(n): inputNumber = int(input("Enter your next number; ")) sumN += inputNumber average = sumN/n print "The sum of the number is; ",sumN print "The average of the number is; ",average Can anybody explain this to me?
MIT 6.001 Structure and Interpretation of Computer Programs, Spring 2005
  • Stacey Warren - Expert
Hey! We 've verified this expert answer for you, click below to unlock the details :)
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
  • jamiebookeater
I got my questions answered at in under 10 minutes. Go to now for free help!
  • anonymous
So this looks like some kind of pseudocode that outlines a process for calculating the average of a series of numbers entered by the user. I.e. \[x _{avg} =\frac{ 1 }{n } \sum_{i=1}^{n} x _{i} \] It looks like the series is 'n' numbers long and that is chosen by the user in: n = int(input ("enter the number input; ")) You also have a variable sumN that starts at 0. Then it looks like you are using some function called 'nCount in range' to keep track of how many numbers the user has entered (that function isn't defined here) but presumably while nCount is less than n you will stay within the 'for' structure prompting the user to enter numbers and adding them to sumN. When you leave the 'for' structure you define a new variable 'average' that gives the average of the series of numbers entered (see eqn.) and you print that average as well as sumN.

Looking for something else?

Not the answer you are looking for? Search for more explanations.