Ask coding questions

← Back to all posts
4.2 Code Practice: Question 2
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
AaryaManoj
WadeConner1
NathanArzola
AshotSedoyan
JenniferMusa
Comments
hotnewtop
Vandesm14

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

JenniferMusa

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

Vandesm14

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

JenniferMusa

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

Vandesm14

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

JenniferMusa
Vandesm14

@JenniferMusa Try running the code on repl.it?

JenniferMusa

@Vandesm14 yes but gave me the same as this

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.

JenniferMusa

@Vandesm14 don't worry I finished it already

Vandesm14

@JenniferMusa

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

JenniferMusa