Hi. Why am I getting "NameError: name 'number' is not defined " for this code? Please help me here as I have no idea

Viewed 42
alphabet=str(input("Enter the alphabet: "))

if "A"==1 and "B"==2 and "C"==3 and "D"==4 and "E"==5 and "F"==6 and "G"==7 and "H"==8 and "I"==9 and "J"==10 and "K"==11 and "L"==12 and "M"==13 and "N"==14 and "O"==15 and "P"==16 and "Q"==17 and "R"==18 and "S"==19 and "T"==20 and "U"==21 and "V"==22 and "W"==23 and "X"==24 and "Y"==25 and "Z"==26:
    number=alphabet

print("The number of the alphabet is",number)
1 Answers

Your expressions return false so number is not defined. add

number = " string is not equal to a number."

before the expression.

I think your trying to get a number value for each character? you should be comparing if the value of alphabet equals a given string, then assigning a numerical value to number. I.E.

if alphabet.upper() == "A": number=1
Related