#πŸ”’ The code works but idk how

29 messages Β· Page 1 of 1 (latest)

shrewd thicket
#

The last else is kinda broken
it doesnt have an if it is called due to
if i remove it, logic changed
indent to left or right, logic changed

(obviously) but i just wanna know how this block is working, lmk if u need additional code, its just 3-4 lines larger

placid breachBOT
#

@shrewd thicket

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.

brave parcel
#

because there's no corresponding if

#

you should delete 1 indentation

shrewd thicket
#

no, its working as i want it to, but there is no corrosponding if, exactly my problem

brave parcel
#

Else should be in a same indentation as if

#

it's in an indentation of for loop

shrewd thicket
#

so for loops have else?

brave parcel
#

No they don't

vivid flicker
#

They do have else πŸ™‚

shrewd thicket
vivid flicker
#

Just not commonly used

shrewd thicket
brave parcel
#

πŸ™„

#

Still that's not what you want I guess

vivid flicker
#

!e

for _ in range(2):
    print("stuff")
else:
    print("For-Else runs when the for block is done executing")
placid breachBOT
#

@vivid flicker :white_check_mark: Your 3.12 eval job has completed with return code 0.

001 | stuff
002 | stuff
003 | For-Else runs when the for block is done executing
shrewd thicket
vivid flicker
#

Note: The else block will NOT be executed if the loop is stopped by a break statement.

shrewd thicket
#

ohh

#

nice

#

well, tysm

vivid flicker
#

if the for loop "breaks" the else doesnt run, if it doesnt break, the else runs.

#

But that aside, your issue probably is that you wanted it on an if statement somewhere πŸ™‚
Let me have al ook

shrewd thicket
vivid flicker
#

Ah okay πŸ™‚ Good stuff

shrewd thicket
#

!close

placid breachBOT
#
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.