欢迎来到我的博客园

python技巧 之 while 跳出三层循环

定义break变量在最里层修改 break_fllag为True

x='Hello {renming},您最喜欢在{nali},您的爱好是{shiqing} '
break_flag=False
while not break_flag:
    name=input('你好,请问如何称呼您?:')
    if name is not None and len(name)!=0 and not break_flag:
        while not break_flag:
            where=input(name+'您最喜欢哪里:')
            if where is not None and len(where)!=0 :
                while not break_flag:
                    things=input(name+'您的爱好是什么:')
                    if things is not None and len(things)!=0 :
                        print(x.format(renming=name,nali=where,shiqing=things))
                        break_flag=True
                        break
                    else:
                        if break_flag:
                            break
                        else:
                            continue
            else:
                if break_flag:
                    break
                else:
                    continue
    else:
        if break_flag:
            break
        else:
            continue

 

posted @ 2018-07-07 01:10  panzq  阅读(315)  评论(0编辑  收藏  举报