流程判断(if...else)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了流程判断(if...else)相关的知识,希望对你有一定的参考价值。
当用户输入密码时候,如果输入正确会输出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
本文出自 “小菜鸟” 博客,请务必保留此出处http://baishuchao.blog.51cto.com/12918589/1932908
以上是关于流程判断(if...else)的主要内容,如果未能解决你的问题,请参考以下文章