#πŸ”’ Loops ( If anybody is willing to help I'd be grateful.)

69 messages Β· Page 1 of 1 (latest)

broken flax
#

!e ```py
user_in = float(input())

while user_in/8.0:
print(user_in)
user_in>=1.0```

deep fractalBOT
#

@broken flax

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.

#

@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
broken flax
#

!e ```py
user_in = 64.0

while user_in/8.0:
print(user_in)
user_in>=1.0```

deep fractalBOT
#

@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

broken flax
#

output should be 8.0

#

and 1.0

pliant hamlet
#

can you explain what while user_in/8.0 does @broken flax?

broken flax
#

divides, i believe

pliant hamlet
#

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

broken flax
#

that makes sense

pliant hamlet
#

so, what is the condition under which you would end the loop?

broken flax
#

When user_in is less than or equal to 1.0

pliant hamlet
#

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.

broken flax
#
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)```

deep fractalBOT
#

@broken flax :warning: Your 3.12 eval job has completed with return code 0.

[No output]
pliant hamlet
#

@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?

broken flax
#

so should there be an else statement?

pliant hamlet
#

No

#

the while loop ends when the condition becomes false

broken flax
#

sorry, I'm not understanding.

pliant hamlet
#

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?

broken flax
#

Yeah because it will only excute certain numbers and not others

#

is that wht you mean?

pliant hamlet
#

once that ceases to be true, the loop will end.

broken flax
#

can you show me an example because I'm lost

#
while user_in >= 1.0:
  print(user_in)```
pliant hamlet
#

!e

num = 5
while num > 3:
    print(num)
    num -= 1
deep fractalBOT
#

@pliant hamlet :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | 5
002 | 4
pliant hamlet
#

@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?

broken flax
#

I think that makes sense yeah

pliant hamlet
broken flax
#

!e py user_in=64.0 while user_in > 1.0: print(user_in) user_in -= 1.0

deep fractalBOT
#

@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

broken flax
#

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```

deep fractalBOT
#

@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
broken flax
#

I'm getting closer its just that 64.0 i need to get rid of

pliant hamlet
broken flax
#

I am not sure

#

because 64 runs through the loop?

pliant hamlet
broken flax
#

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.

pliant hamlet
broken flax
#

Oh alright thanks

broken flax
pliant hamlet
#

@broken flax did it work?

broken flax
#

!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)

deep fractalBOT
#

@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
broken flax
pliant hamlet
broken flax
#

yeah, thats good

pliant hamlet
#

0.125 is not rounded to the nearest tenth, though.

broken flax
#

!e py user_in= 64.0 while user_in>=1.0: user_in=(user_in//8) print(user_in)

deep fractalBOT
#

@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
broken flax
#

im not sure how to round it

pliant hamlet
deep fractalBOT
#

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__`.
deep fractalBOT
#
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.