python - 当我输入用户名时,未显示 "good job"

标签 python

import time

def Scenario2():

        film_comedy = ['Anchorman','The Hangover','Ted']
        film_horror = ['The Exorcist','The Shining','Scream']
        film_action = ['Die Hard','The Matrix','Batman']
        film_animation = ['Toy Story','The Incredibles','The Lion King']

        print("Hello, welcome to the online streaming service")
        username = len(input("Please Enter a username between 4 and 12 characters: "))

        while username < 4 or username > 12:
            print("That username is not within the boundaries")
            username = len(input("Please Enter a username between 4 and 12 characters: "))

        password = input("Now enter a password: ")
        password1 = input("Please re-enter the password: ")

        if password1 == password:
            print("Congratualtions on your new account")


        while password1 != password:

            print("They don't match")
            password = input("Now enter a password: ")
            password1 = input("Please re-enter the password: ")

            if password1 == password:
                    print("Congratualations on your new account")


        usernameinput = input("Please Enter your username: ")

        if usernameinput == username:

                print("Great job")

        while usernameinput != username:

                print("That is the incorrect Username")
                usernameinput = input("Please Enter your username: ")

                if usernameinput == username:
                        print("Great job")


Scenario2()

每当我输入用户名时,输入与用户名相同的内容。它并没有说做得好,而是说它是错误的。

我可以得到一些帮助吗?

最佳答案

    while usernameinput != username:

        print("That is the incorrect Username")
        usernameinput = input("Please Enter your username: ")

        if usernameinput == username:
                print("Great job")

这不起作用,因为您在此 while 之前分配了 username = len(input("Please Enter a username between 4 to 12characters: "))循环,重命名变量以使其正常工作。

关于python - 当我输入用户名时,未显示 "good job",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46042585/

相关文章:

python - Numpy savetxt 类型错误

python - 属性错误: 'function' object has no attribute 'bar' in pandas

python - 机器人测试接收到的 unicode 与从 python 关键字发送的不同

python - 用 pandas 平均二维地理数据

python - MongoDB 和 web2py : Working with ObjectIds

python - 将多个文件中的数据插入到多个表中

python pandas 分箱数值范围

python - 使用 with 语句打开文件列表

python - 为什么redis可以绑定(bind)到这个端口,而我不能通过python?

python - 计算 Django 中模型属性的总和