Skip to content

Instantly share code, notes, and snippets.

@gitaficionado
Created March 11, 2021 16:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gitaficionado/ae1491cc3d6c51c297eed696f1d0251d to your computer and use it in GitHub Desktop.
Save gitaficionado/ae1491cc3d6c51c297eed696f1d0251d to your computer and use it in GitHub Desktop.
Ask the user how many numbers for which they want to calculate the sum. Using a for loop, prompt the user to enter that many numbers, one-by-one, keeping track of the sum. At the end, after the user entered all numbers, output the sum.
'''
3. Ask the user how many numbers for which they want to calculate the sum. Using a for loop, prompt the user to enter that many numbers, one-by-one, keeping track of the sum. At the end, after the user entered all numbers, output the sum.
Create a variable and assign it the value of 0
Prompt the user for how many numbers they have
With a for loop, set it to repeat enough times to get all their values
Prompt the user for a number
Add that number to the variable that started as 0
Output to the user, the sum of all values
'''
# Loop Problem 3
answer = ___
total = ____
answer = int(input("How many numbers do you have? "))
for i in range(______):
num = int(input("Please enter a number: "))
total = total + ____
print("The sum of all of your values is: " + str(______))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment