if、elif和len(x)的问题

2024-09-29 23:23:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图给自己编写一个登录和注册脚本,但我的用户名定义有问题。我可以不使用任何验证方法运行代码,但如果使用了验证方法,代码似乎总是会中断。你知道吗

    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()

有人知道它为什么不起作用吗?我不知道它为什么不起作用。你知道吗


Tags: theto方法代码ininputyourlen

热门问题