0
cont = "y"

while cont == "y":
    day = input("Enter today's day: ")

    if day == "monday" or "Monday":
        day = day.upper()
        if day in my_class:
            print ("You have ",my_class[day], " today")

    elif day == "tuesday" or "Tuesday":
        day = day.upper()
        if day in my_class:
            print ("You have ",my_class[day], " today")

    elif day == "wednesday" or "Wednesday":
        day = day.upper()
        if day in my_class:
            print ("You have ",my_class[day], " today")

    elif day == "thursday" or "Thursday":
        day = day.upper()
        if day in my_class:
            print ("You have ",my_class[day], " today")

    elif day == "friday" or "Friday":
        day = day.upper()
        if day in my_class:
            print ("You have ",my_class[day], " today")

    else:
        print ("Enter a valid day")

    cont = input("Type y to continue: ")

I want it to print what the else says if an invalid date is put in but it skips over to printing "Type y to continue: "

Arkistarvh Kltzuonstev
  • 6,824
  • 7
  • 26
  • 56
John Boi
  • 21
  • 3
  • 1
    The `or` statement is not doing what you think it is. Should be `if day == 'Monday' or day == 'monday'` – C.Nivs Sep 22 '19 at 01:57

1 Answers1

1

The problem is with your use of the or operator:

if day == "monday" or "Monday":

Is translated as "is day == "monday" truthy, or is "Monday" truthy?" Since "Monday" is always truthy (since it is a non-empty string), you will always get this if block. Your ifs and elifs should look more like:

if day == "monday" or day == "Monday":

One way to shorten it would be:

if day in ["monday","Monday"]:

However, a cleaner way to do this same check would be:

if day.lower() == "monday":

This will make your check case insensitive. The rest of your elif statements should do the same.

elethan
  • 16,408
  • 8
  • 64
  • 87