#๐Ÿ”’ While Loop (need quick help pls)

32 messages ยท Page 1 of 1 (latest)

frosty crow
#
result = 0
user_number = int(input())

while user_number <= 0:
    user_number += 0
    print(user_number, end=' ')
    user_number= int(input())

print(result)```
proper kelpBOT
#

@frosty crow

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

frosty crow
#

The goal is to keep adding integers less than 0 until positive number or number equal to 0 terminates the loop

rigid oriole
#

what's the issue

frosty crow
#

Hey this is my current code

#
result = 0
user_number = int(input())

while user_number <= 0:
    user_number += 0
    print(user_number, end=' ')
    user_number= int(input())

print(result)```
rigid oriole
#

right, so you never change the variable result

frosty crow
#

Wdym?

rigid oriole
#

result is set to 0 at the start of the code, then printed as 0 at the end, that's all that happens to it

frosty crow
#

oh I see

#

so i need result to equal last integer read right?

#

to add to new integer read

rigid oriole
#

you need to be adding the new integers to the result

frosty crow
#

what would that look like

#

a little confused

frosty crow
rigid oriole
#

user_number += 0 this doesn't do anything right now, try rewriting this such that the input is added to result

frosty crow
#
result= user_number + result```
rigid oriole
#

try running it

frosty crow
# rigid oriole try running it

!e ```py
result = 0
user_number = int(input())

while user_number <= 0:
result= user_number + result
print(user_number, end=' ')
user_number= int(input())

print(result)```

proper kelpBOT
#

@frosty crow :x: Your 3.12 eval job has completed with return code 1.

:warning: Note: input is not supported by the bot :warning:

001 | Traceback (most recent call last):
002 |   File "/home/main.py", line 2, in <module>
003 |     user_number = int(input())
004 |                       ^^^^^^^
005 | EOFError: EOF when reading a line
frosty crow
#

This what I got^

rigid oriole
#

so what is the problem in test case 1?

somber valley
#
print(user_number, end=' ')
#

remove this

frosty crow
#

Oh I see, it worked

#

Thanks

proper kelpBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.