-7

The program needs to accept and match any upper and lower case versions of the word, which is why .lower() is used. When this is ran and 'January' is entered, the else line is printed instead of the if line.

month = input("\nPlease enter the month\n")
if month.lower == ("january"):
    month = int(1)
    print(month)
elif month.lower == ("february"):
    month = int(2)
    print(month)
elif month.lower == ("march"):
    month = int(3)
    print(month) #etc.
else:
    print("That is not a month\n")
  • 1
    Not causing the problem but you shouldn't need the brackets around the strings. `if month.lower() == "january":` should work. – Holloway Jan 28 '15 at 20:48

1 Answers1

12

You need to call the method:

month.lower() == 'march'

The method is an object too, and without calling it you are comparing that method with a string. They'll never be equal:

>>> month = 'January'
>>> month.lower
<built-in method lower of str object at 0x100760c30>
>>> month.lower == 'January'
False
>>> month.lower == 'january'
False
>>> month.lower() == 'january'
True
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343