Python if、elif和len(x)的问题

Python if、elif和len(x)的问题,python,Python,我试图给自己编写一个登录和注册脚本,但我的用户名定义有问题。我可以在没有验证方法的情况下运行代码,但是有了它,代码似乎总是会崩溃 usernameloop = 1 while usernameloop == 1: username = input("Please input your desired username.") if len(username) >> 20: print("Unable to choo

我试图给自己编写一个登录和注册脚本,但我的用户名定义有问题。我可以在没有验证方法的情况下运行代码,但是有了它,代码似乎总是会崩溃

    usernameloop = 1
    while usernameloop == 1:
        username = input("Please input your desired username.")
        if len(username) >> 20:
            print("Unable to choose that username, you need to have less than 20 characters in your username.")
        elif len(username) >= 4 and len(username) <= 20:
            print("Username Selected. Your username is:", username)
            time.sleep(1)
            usernameloop = 0
            break

# This is the problematic statement. It doesn't work if this is in and always goes to this statement even if the validation should be correct.

        elif len(username) << 4: 
            print("Unable to choose that username, you need 3 or more characters in your username.")
        else:
            print("An Unknown Error Occurred, contact x with the screenshot of the conversation history.")
            time.sleep(10)
            exit()
usernameloop=1
当usernameloop==1时:
用户名=输入(“请输入您想要的用户名。”)
如果len(用户名)>>20:
打印(“无法选择该用户名,您的用户名必须少于20个字符。”)
如果len(username)>=4且len(username)使用单个“”代替“”,则一切正常。

使用单个“”代替“”,则一切正常。

>
是一个

是一个


>
是您正在使用的
>
>20
对于少于2**20个字符的字符串将为0<代码>len(用户名)已修复,谢谢您的帮助!您正在使用
>
len(用户名)>>20
对于少于2**20个字符的字符串将为0<代码>len(用户名)已修复,谢谢您的帮助!