#π Loops ( If anybody is willing to help I'd be grateful.)
69 messages Β· Page 1 of 1 (latest)
@broken flax
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.
@broken flax :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 1, in <module>
003 | user_in = float(input())
004 | ^^^^^^^
005 | EOFError: EOF when reading a line
!e ```py
user_in = 64.0
while user_in/8.0:
print(user_in)
user_in>=1.0```
@broken flax :x: Your 3.12 eval job has completed with return code 143 (SIGTERM).
001 | 64.0
002 | 64.0
003 | 64.0
004 | 64.0
005 | 64.0
006 | 64.0
007 | 64.0
008 | 64.0
009 | 64.0
010 | 64.0
011 | 64.0
... (truncated - too many lines)
Full output: too long to upload
can you explain what while user_in/8.0 does @broken flax?
divides, i believe
user_in/8.0 performs division. but you have it in the while statement. which means that the loop will keep going until user_in / 8.0 is zero
not less than zero--until it's exactly zero.
which isn't what you want
that makes sense
so, what is the condition under which you would end the loop?
When user_in is less than or equal to 1.0
okay, so write a while statement that reflects that.
remember: the while loop will continue while the condition is true, not while it's false.
user_in = 64.0
while user_in <= 1.0:
print(user_in//8.0)```
!e ```py
user_in = 64.0
while user_in <= 1.0:
print(user_in//8.0)```
@broken flax :warning: Your 3.12 eval job has completed with return code 0.
[No output]
@broken flax your while condition is user_in <= 1.0. but the while loop will only execute if the condition is true. do you see the problem?
so should there be an else statement?
sorry, I'm not understanding.
every time the while loop starts, it will check if user_in <= 1.0 is true. and if it is, then the loop body will execute. otherwise, it will not.
do you see why user_in <= 1.0 is not what you want, in that context?
Yeah because it will only excute certain numbers and not others
is that wht you mean?
that's not it.
you need to reverse the condition. you want the loop to run while user_in is greater than 1.
once that ceases to be true, the loop will end.
!e
num = 5
while num > 3:
print(num)
num -= 1
@pliant hamlet :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 5
002 | 4
@broken flax this loop runs while num > 3 is true. which means that it ends when num <= 3 becomes true.
the loop runs while the condition is true. not until the condition is true. make sense?
I think that makes sense yeah
can you show updated code that fixes the while statement?
!e py user_in=64.0 while user_in > 1.0: print(user_in) user_in -= 1.0
@broken flax :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 64.0
002 | 63.0
003 | 62.0
004 | 61.0
005 | 60.0
006 | 59.0
007 | 58.0
008 | 57.0
009 | 56.0
010 | 55.0
011 | 54.0
... (truncated - too many lines)
Full output: https://paste.pythondiscord.com/3M34NCA5EJBTKUHSI6IHQL7DUQ
I apologize, I am completely lost
i thought it made sense
!e ```py
user_in = 64.0
while user_in >= 1.0:
print(user_in)
user_in = user_in/8```
@broken flax :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 64.0
002 | 8.0
003 | 1.0
I'm getting closer its just that 64.0 i need to get rid of
why do you think it prints three times and not two?
what does it mean for 64 to "run through the loop"?
please ping me when you respond to me.
Im not sure how to ping, I've never done that before. But I think it just iterates right, i think thats the word for it. Its either false or true which in this case is true becasue 64.0 is greater than 1.0.
you can ping people with one of these two ways.
the print statement is the first one in the loop. the statement after it is the one that updates the value of user_in.
Oh alright thanks
So it needs to be new value of user_in first than print statement
try that.
@broken flax did it work?
!e py user_in= 64.0 while user_in>=1.0: user_in=(user_in/8) print(user_in)
!e py user_in= 64.0 while user_in>=1.0: user_in=(user_in/8) print(user_in)
@broken flax :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 8.0
002 | 1.0
003 | 0.125
This is what I ended up with
are you okay with that?
yeah, thats good
0.125 is not rounded to the nearest tenth, though.
!e py user_in= 64.0 while user_in>=1.0: user_in=(user_in//8) print(user_in)
@broken flax :white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | 8.0
002 | 1.0
003 | 0.0
im not sure how to round it
!docs round
round(number, ndigits=None)```
Return *number* rounded to *ndigits* precision after the decimal point. If *ndigits* is omitted or is `None`, it returns the nearest integer to its input.
For the built-in types supporting [`round()`](https://docs.python.org/3/library/functions.html#round), values are rounded to the closest multiple of 10 to the power minus *ndigits*; if two multiples are equally close, rounding is done toward the even choice (so, for example, both `round(0.5)` and `round(-0.5)` are `0`, and `round(1.5)` is `2`). Any integer value is valid for *ndigits* (positive, zero, or negative). The return value is an integer if *ndigits* is omitted or `None`. Otherwise, the return value has the same type as *number*.
For a general Python object `number`, `round` delegates to `number.__round__`.
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.