Python 创建用户名和密码程序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44663389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python creating username and password program
提问by Polly the Programmer
I am just a beginner programmer as of right now, and I am trying to create a username/password program. Here is my code below:
我现在只是一个初学者程序员,我正在尝试创建一个用户名/密码程序。这是我的代码如下:
username = 'Polly1220'
password = 'Bob'
userInput = input("What is your username?\n")
if userInput == username:
a=input("Password?\n")
if a == password:
print("Welcome!")
else:
print("That is the wrong password.")
else:
print("That is the wrong username.")
Whenever I run my program and input the correct password as shown, it always says that the password is incorrect.
每当我运行我的程序并输入正确的密码时,它总是说密码不正确。
回答by Ajax1234
You need to assign the second input statement to userInput:
您需要将第二个输入语句分配给 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.")
回答by Damián Rafael Lattenero
You forget asign the variable:
您忘记分配变量:
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.")