您的位置:首页 > 编程语言 > Python开发

python流程判断之多层循环学习笔记

2017-04-16 20:31 309 查看
passwd = 'test' 创建一个变量
logout_flag = False 如果登录等于假,继续输入密码
for i in range(4): 循环4次
user_input = raw_input("please input your passwd:").strip() 赋值用户输入passwd次数
if len(user_input) == 0:continue 从0开始计入次数,continue 持续的意思
if user_input == passwd: 判断用户输入密码
while True: 如果为真则登录 选择如下选项
print "welcome login!"
user_choice = raw_input('''
1. run a cmd
2. send a file
3. exit this level
4. exit the whole system
''').strip()
user_choice = int(user_choice)
if user_choice == 1: 直到循环到4次之后推出
print "going to run cmd"
if user_choice == 2:
print "going to sed a file"
if user_choice == 3:
print "going to exit this level"
break
if user_choice == 4:
logout_flag = Ture
break break代表退出while True:循环
if logout_flag:
print "going to logout"
break break代表退出for循环
print "---going to do something else...."
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  判断 python 循环