我现在只是一个初学者程序员,我正在尝试创建一个用户名/密码程序.这是我的代码如下:
username = 'Polly1220'
password = 'Bob'
userInput = input("What is your username?\n")
if userInput == username:
input("Password?\n")
if userInput == password:
print("Welcome!")
else:
print("That is the wrong password.")
else:
print("That is the wrong username.")
每当我运行我的程序并输入正确的密码时,它总是说密码不正确.
解决方法:
您需要将第二个输入语句分配给userInput:
if userInput == username:
userInput = input("Password?\n")
if userInput == password:
print("Welcome!")
else:
print("That is the wrong password.")
else:
print("That is the wrong username.")
标签:python
来源: https://codeday.me/bug/20190717/1486923.html