当用户输入密码时候,如果输入正确会输出welcom user login,如果输入错误会输出invalid username or password
#!/usr/bin/env python # -*- coding:utf-8 -*- import getpass _username = "xcn" _password = "admin" username = input("username:") password = getpass.getpass("password:") print(username, password) if _username == username and _password == password: print("welcome user {name} login ..." .format(name=username)) else: print("invalid username or password!") ce
#!/usr/bin/env python # -*- coding:utf-8 -*- age_of_xcn = 20 guess_age = int(input("guess age:")) if guess_age == age_of_xcn: print("yes,you got it") elif guess_age > age_of_xcn: print("think smaller") else: print("think bigger") 执行结果: guess age:12 think bigger guess age:22 think smaller