#๐ While Loop (need quick help pls)
32 messages ยท Page 1 of 1 (latest)
@frosty crow
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.
The goal is to keep adding integers less than 0 until positive number or number equal to 0 terminates the loop
what's the issue
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)```
right, so you never change the variable result
Wdym?
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
oh I see
so i need result to equal last integer read right?
to add to new integer read
you need to be adding the new integers to the result
would I be adding after new integer?
user_number += 0 this doesn't do anything right now, try rewriting this such that the input is added to result
result= user_number + result```
like that?
^
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)```
@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
so what is the problem in test case 1?
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.