Help with elif not running

Hello, I’m trying to write a section of a program that converts month names to numbers. My teacher says we have to do it using else and if and elif statements, not with any month functions. The original if statement is running but none of the elif or else statements afterwards are. I’m not getting any errors, they just simply arent running. The indentation is correct, and there arent any extra lines in between or anything, just not sure why my elifs arent running. Also, even for the original if statement, when I put a print test there to see if it was working, it seemed to print it no matter what the input was. How do I ensure that it actually recognizes the text and turns it into numbers? Right now it just seems to make A=13 no matter what the input is. Here is the code:

    A=input("Please enter the name of the month: ")
    if(A=="January" or "january"):
        A=13    
    elif(A=="February" or "february"):
        A=14
    elif(A=="March" or "march"):
        A=3
    elif(A=="April" or "april"):
        A=4
    elif(A=="May" or "may"):
        A=5
    elif(A=="June" or "june"):
        A=6
    elif(A=="July" or "july"):
        A=7
    elif(A=="August" or "august"):
        A=8
    elif(A=="September" or "september"):
        A=9
    elif(A=="October" or "october"):
        A=10
    elif(A=="November" or "november"):
        A=11
    elif(A=="December" or "december"):
        A=12
    else:
        print("incorrect input. Please try again")

The expression inside the first if can be parsed as
(A=="January") or ("january")

The first part depends on A, but the second part does not. As a non-empty string, "january" is always true.

Alternatives might be:

A=="January" or A=="january"
A in ["January", "january"]
A.lower() == "january"

I tried these and it still didnt seem to work. Here is the output:

Please enter the name of the month: January
13

Please enter the name of the month: hjashdak
13

Please show your code. I’m not sure which (if any) of the suggestions you might have tried or how you’ve implemented it.

A=input("Please enter the name of the month: ")
if(A==“January”) or (“january”):
A=13

A=input("Please enter the name of the month: ")
if A==“January” or A==“january”:
A=13

A=input("Please enter the name of the month: ")
if A.lower()==“january”:
A=13

These all work for it to recognize the text, but they still don’t seem to allow my elifs to run

1 Like

The first is incorrect. The if will be true for any input.

The second two seem fine, but you’ve only shown a snippet, so I’m assuming the error is elsewhere in your code. Here’s a short example with if/else.

for A in ["january", "January", "rutabaga"]:
    if A.lower() == "january":
        print(f"{A} matches january")
    else:
        print(f"{A} isn't a match for january")

Output:

january matches january
January matches january
rutabaga isn't a match for january

I have the same problem, the “or” hinders my “elif”