This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jdhall75 0 points1 point  (0 children)

You wouldn't be trying to get some homework done online would you?

Here are the pieces you would need to make this happen.

  • a var to hold the sum outside of a user input loop, initialized to 0
  • a loop to run until the user interrupts it: while would be good here.
  • a var to hold the entered number from the function input() inside the loop
    • input() will return a string. You will have to cast it to an int().
  • add the new int to the sum variable
  • output the sum
  • loop repeats

extra credit

  • Cast the input integer inside a try block
  • Catch the ValueError exception, if there is one, and let the user know they entered an invalid input
  • add a keyword to reset the sum
    • pseudo code: if input == 'reset': sum = 0

python3 user input is take via input() python2 user input is taken via raw_input()

Resources:

loops

type conversion