← Back to Community
4.2 Code Practice: Question 2
Profile icon
JenniferMusa

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

Voters
Profile icon
AaryaManoj
Profile icon
WadeConner1
Profile icon
NathanArzola
Profile icon
AshotSedoyan
Profile icon
JenniferMusa
Comments
hotnewtop
Profile icon
Vandesm14

What have you tried so far? Could you share your code?
(Also, what language?)

Profile icon
JenniferMusa

@Vandesm14
sum = 0
c = 0
while(sum<100):
sum = sum + x
print("sum:"+ str(sum))
print("Numbers entered: " +str(c))

Profile icon
Vandesm14

@JenniferMusa Does it work? What problem(s) are you facing?

Profile icon
JenniferMusa

@Vandesm14 it worked but the only problem is they are asking what x is. sum = sum + x

Profile icon
Vandesm14

@JenniferMusa Who's "they"? Can you send me a screenshot of your issue?

Profile icon
JenniferMusa
Profile icon
Vandesm14

@JenniferMusa Try running the code on repl.it?

Profile icon
JenniferMusa

@Vandesm14 yes but gave me the same as this

Profile icon
Vandesm14

@JenniferMusa You need to indent the code you want inside the while loop. Python does not use brackets: instead, it uses indentation to figure out which code is in which block.

Profile icon
JenniferMusa

@Vandesm14 don't worry I finished it already

Profile icon
Vandesm14

@JenniferMusa

Please mark my comment as the answer if I resolved your issue 👍

Profile icon
JenniferMusa