195k views
2 votes
4.2 Code Practice: Question 1

Write a program that inputs numbers and keeps a running sum. When the sum is greater than 100, output the sum as well as the count of how many numbers were entered.

Sample Run

Enter a number: 1
Enter a number: 41
Enter a number: 36
Enter a number: 25

Sum: 103
Numbers Entered: 4

Hint: If you get an EOF error while running the code you've written, this error likely means you're asking for too many inputs from the user.

1 Answer

5 votes

In python:

total = 0

i = 0

while total <= 100:

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

i += 1

total += number

print("Sum: {}".format(total))

print("Numbers Entered: {}".format(i))

I hope this helps!

User Solerous
by
6.7k points