开发者社区 问答 正文

如何用多个if条件做while语句?

在这里开始学习python,想通过我的在线课程做一些修改:

while True:
    print("What is your name?")
    name = input()
    character = int(len(name))
    if character < 3 or character > 20:
        print("Name can only less than 3 character and no more than 50 character")
    else:
        print(f"Welcome back, {name}")
        break

基本上我想我的代码做: 我的代码完全按照它说的做,但是我想知道我是否可以通过每个条件定制通知。任何帮助都将非常感谢,因为这是我可以在stackoverflow上浏览到的。(或者是我能理解的最简单的一个) 问题来源StackOverflow 地址:/questions/59466712/how-to-do-while-statement-with-multiple-if-condition

展开
收起
kun坤 2019-12-25 09:42:22 648 分享 版权
1 条回答
写回答
取消 提交回答
  • outer:while(true){
    for(){
    break outer;//这样就可以跳出while
    }
    }

    2019-12-25 11:45:38
    赞同 展开评论
问答地址: