#๐Ÿ”’ skipping or not doing if/elif statements

18 messages ยท Page 1 of 1 (latest)

oak chasm
#

I am trying to have a user (me) enter specfic data points and it spew out what those data points are based on specific criteria
No matter what I answer the first input with (online or irl are the two answers) it skips over either the last if/elif statement if i say irl, or both the first and last if/elif statement if i say online. please help me figure out where i messed up (I"m stil very new and appreciate this)

supple gladeBOT
#

@oak chasm

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.

oak chasm
#

for example if i answer the first question "online" it doesnt set the Event_level to "No" and instead just goes straaight to the Yes option

#

it seems the problem lies in the elif i set up for Event_level Y/N and idk what i did wrong

west steeple
#

if Event_level == "Y" or "Yes":

#

!or

supple gladeBOT
#
The or-gotcha

When checking if something is equal to one thing or another, you might think that this is possible:

# Incorrect...
if favorite_fruit == 'grapefruit' or 'lemon':
    print("That's a weird favorite fruit to have.")

While this makes sense in English, it may not behave the way you would expect. In Python, you should have complete instructions on both sides of the logical operator.

So, if you want to check if something is equal to one thing or another, there are two common ways:

# Like this...
if favorite_fruit == 'grapefruit' or favorite_fruit == 'lemon':
    print("That's a weird favorite fruit to have.")

# ...or like this.
if favorite_fruit in ['grapefruit', 'lemon']:
    print("That's a weird favorite fruit to have.")
west steeple
#

This is a common mistake โ˜๏ธ

#

@oak chasm

oak chasm
#

oh okay gotcha

west steeple
#

!e you can see here

Event_level = "No"
print(bool(Event_level == "Y" or "Yes"))
supple gladeBOT
oak chasm
#

i swear this gets me so much im so sorry!

west steeple
#

Don't be ๐Ÿ™‚ That's what these help channels are for

oak chasm
#

thanks still ye

supple gladeBOT
#
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.