131,049 views
3 votes
3 votes
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

User Otake
by
2.8k points

1 Answer

17 votes
17 votes

Answer:n = int(input("How many numbers do you want to sum? "))

total = 0

for x in range(n):

total += int(input("Enter a number: "))

print("Sum: "+str(total))

Step-by-step explanation:

User Brooks
by
2.8k points