for / while 循环

luck_num = 10

num = 0
while luck_num != num:
    num = int(input('please input you num:'))
    if num > luck_num:
        print('Greater than lucknum')
    elif num < luck_num:
        print('Less than lucknum')
print('This number is lucknum')

for i in range(3):
    num = int(input('please input you number:'))
    if num > luck_num:
        print('Greater than lucknum')
    elif num < luck_num:
        print('Less than lucknum')
    else:
        print('Yes this number is lucknumber')
        break
else:  # 正常执行完循环的话,执行里面语句,非正常的话跳过这个else
    print('Try many,only three')

#多层嵌套循环
for i in range(5):
    for m in range(10):
        if m < 5:
            continue
        if i > 3:
            break
        print(str(m) + '  ' + str(i))
    else:#正常循环结束才执行else里面的代码
        continue
    break

 

posted @ 2017-03-03 22:14  破斧呈粥  阅读(114)  评论(0编辑  收藏  举报