# Author:iwanghang # getpass 在pycharm中无效,请用cmd运行 import getpass _username = "iwanghang" _password = "123123" username = input("username:") password = getpass.getpass("password:") if _username == username and _password == password: print("Welcome user {name} login...".format(name=username)) else: print("Invalid username or password!")
Debug Output:
(venv) C:\PycharmProjects\20180111\01>python test04.py username:iwanghang password: Welcome user iwanghang login... (venv) C:\PycharmProjects\20180111\01>python test04.py username:iwanghang password: Invalid username or password!