Ask coding questions

← Back to all posts
4.2 Code Practice: Question 2
JenniferMusa (8)

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

Comments
hotnewtop
Vandesm14 (2639)

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

JenniferMusa (8)

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

Vandesm14 (2639)

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

JenniferMusa (8)

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

Vandesm14 (2639)

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

Vandesm14 (2639)

@JenniferMusa Try running the code on repl.it?

JenniferMusa (8)

@Vandesm14 yes but gave me the same as this

Vandesm14 (2639)

@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 (8)

@Vandesm14 don't worry I finished it already

Vandesm14 (2639)

@JenniferMusa

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