例子一:
代码中通过 import getpass 引入模块getpass模块,可以在输入密码的时候不直接显示明文密码,但这个在PyCharm中运行有点问题。
# Author: Alex Chen import getpass _username = "alex" _password = "cx123456" username = input("username=") password = getpass.getpass("password=") if username == _username and password == _password: print("login successful") else: print("failed")
例子二:加入大小判断
# Author: Alex Chen real_age = 45 age = int(input("please input age:")) if age == real_age: print("cool, you got it.") elif age > real_age: print("should be smaller.") else: print("should be bigger.")