Python 条件结构有问题

Got a problem with Python conditional structure

我的 python 代码中有一个 if 条件结构,我对它的执行方式有疑问... 我希望第一个嵌套 if 在返回 false 时打印 The input choice you entered is out of range") 但它执行 else 中的代码,即第二个嵌套 if 中的 you entered 4,我希望它执行第一个嵌套 if 的 false 对应项 print("nThe input choice you entered is out of range"),我是不是缩进错了?请帮帮我

message=input("Enter the message you want encrypted")
if(message.isalpha()& message.__len__()!=0):
    options=("1. Substitution Cypher","2.Playfair Cypher","3. Transposition Cypher", "4. Product Cypher","RSA Cypher")
    print("Choose an encryption Cypher you would like to use?")
    print(options[0])
    print(options[1])
    print(options[2])
    print(options[3])


    choice=int(input("Please reply with a number for choice of Cypher"))
    ##USER NEEDS CHOICE OF encryption algorithm to use
    if(choice>=1&choice<=4):
        if(choice==1):
            print("You chose 1")
        elif(choice==2):
            print("You chose 2")
        elif(choice==3):
          print("You chose 3")
        else:
         print("You chose 4")
    else:
        print("nThe input choice you entered is out of rage")
else:
    print("User input is required in form of alphabet format")
if(choice>=1&choice<=4):

这不是你想的那样。由于 operator precedence & 比比较更粘所以上面相当于

if(choice>=(1&choice)<=4):

如果要保留&需要加括号如下

if((choice>=1)&(choice<=4)):

但是请注意,由于 python 的一项功能,您可能会编写

if(1<=choice<=4):

得到相同的结果