#đź”’ If proceeding with wrong conditions

10 messages · Page 1 of 1 (latest)

weary wagon
#

I’m new to python (and coding as a whole), and I’m making a time left in class thing. First I’m using datetime to get the weekday, but I went ahead and tested some other days. Other numbers aren’t working as well.

weekDay = 1
if weekDay >= 0 and weekDay <=.4:
if weekDay == 0 or 4:
print("Mon/Fri Schedule")
elif weekDay == 1 or 3:
print( "Tues/Thur Schedule")
elif weekDay == 2:
print("Wed Schedule")
else:
print ("There's no school ye goof”)

After running weekDay set to 1, it returns “Mon/Fri Schedule” instead of “Tues/Thur schedule”

Is my syntax wrong?

covert mauveBOT
#

@weary wagon

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.

spiral bloom
#

!or-gotcha

covert mauveBOT
#
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.")
spiral bloom
bold vortex
#

You accidentally added a dot

<=.4:
  ^
bold vortex
lofty raft
#

The quotes seem to also not be properly closed since you used ” instead of "

print ("There's no school ye goof”)
                                 ^
covert mauveBOT
#
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.