一、密码输入不显示
方法:getpass
Import getpass
username = input("username:")
password = getpass.getpass("password:")
print(username,password)
结果输出:
[[email protected]~]#./hello.py
username:user
password:
(‘user‘,‘123‘)
[[email protected]~]#
二、if判断
#Author:RobinWen
_username = "Robin"
_password = "123456"
username = input("username:")
password = input("password:")
if_username == username and _password == password:
print("Welcome user {name} logo in!".format(name=username))
else:
print("Invalid username or password!")
结果输出:
(1)True
username:Robin
password:123456
Welcome user Robin logo in!
(2)False
username:Robin
password:111
Invalid username or password!
三、年龄猜测-if判断
#Author:RobinWen
my_age=25
guess_age = int(input("Age:"))
if guess_age == my_age:
print("yes,you got it!")
elif guess_age > my_age:
print("bigger...")
else:
print("smaller...")
原文地址:https://www.cnblogs.com/bazingafraser/p/8523717.html