#๐Ÿ”’ Easy question, confused because im new

22 messages ยท Page 1 of 1 (latest)

polar gustBOT
#

@atomic phoenix

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.

atomic phoenix
#

Is it because since the first answer is true, the rest wont be executed? I cant find a solid answer and dont really trust AI. Again, thanks in advance

crimson sluice
#

You are correct - since the checks are chained using elifs, each condition will only be checked if the previous one failed.
In your example the first condition is greater than 2 (which is true for an input of 1000) which causes code under the first condition to be run, while preventing the rest from executing.

spring badger
# atomic phoenix Is it because since the first answer is true, the rest wont be executed? I cant ...

think of an elif block like saying else if.

essentially meaning, that the next part(/if-block) won't run if the current one checks out; or in reverse, it'd only run when the previous one fails.

it'd go from top to buttom. However there's a flaw in this logic.

Since things larger than 500 would also be larger than 2 โ€” it'd run and stop at the first check (cash >= 2), hence only that (in this case) would end up executing.

#

unless ofc when it's less than 2 - this would end up with the else-block executing.

supple dagger
#

I wouldn't be surprised if that's to test that they understand the order the checks are done in.

heady needle
#

the answer is 3rd?

#

bruh

supple dagger
heady needle
#

now i get bruhh

#

am i this bad

#

dang

supple dagger
# heady needle am i this bad

Just practice use of if statements. Given they'll be used in basically any program you ever write, you should get used to them relatively quickly.

heady needle
#

i think i got confused

atomic phoenix
#

Okay! So a correct way to write it would be to clarify that the next option ($15+) would not be true under the first Boolean statement?

supple dagger
atomic phoenix
#

Alright. Thank you, it makes sense now

supple dagger
# heady needle goto end

I'm not sure what you mean. What I was hinting at was to reverse the order of the checks. Check for larger numbers first, and then end with the sock check.

polar gustBOT
#
Python help channel closed for inactivity

This help channel has been closed. 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.