输入密码时,密码看不见,即密文:
import getpass #导入getpass标准库,直接调用就可以密文 username = input("username:") password = getpass.getpass("password:") print(username,password)
if/else循环
_username='alex' _password='abc123' username=input("username:") password=input("password:") if _username ==username and _password== password: print("Welcome user {name} login...".format(name=username)) else: print("Invalid username or password!")
小游戏:猜数字,猜年龄
age_of_oldboy = 56 guess_age = int(input("guess age:")) if guess_age == age_of_oldboy : print("yes, you got it.") elif guess_age > age_of_oldboy: print("think smaller...") else: print("think bigger!")
猜3次,猜对了就结束,错了就3次机会,用完就没有了。
age_of_oldboy = 56 guess_age = input("gusee age:")