第十一节 if else流程判断
import getpass
username = input("username:")
password = getpass.getpass("password:")
例1
_username = "wang" //赋值要加双引号 如果不加引号 username = wang,这里的wang也代表变量
_password = "123"
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")
输出结果:
username:qang
password:113
invalid username or password
username:wang
password:123
welcome user wang login
例2:
_username = "wang"
_password = "123"
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")
print("123") //只要是自成一派的都要顶格写,不属于if else的子程序,所以会一直输出
输出结果:
username:wang
password:123
welcome user wang login
123
例3:加判断语句
age_of_oldboy=56
guess_age=int(input("guess_age:"))
if age_of_oldboy==guess_age:
print("yes,you got it!")
elif age_of_oldboy>guess_age:
print("think smaller")
else:
print("think older")
输出结果:
guess_age:56
yes,you got it!
guess_age:57
think older
guess_age:20
think smaller
posted on 2019-04-07 14:58 googleWang 阅读(228) 评论(0) 编辑 收藏 举报