Skip to main content
 首页 » 编程设计

python之"while loop"没有中断(使用 Python)

2025年05月04日9zengkefu

这是我的代码:

#Choose Report 
def chooseReport(): 
    print "Choose a report." 
    while True: 
        choice = raw_input("Enter A or B: ") 
        if choice == 'a' or choice == 'A': 
            reportA() 
            break 
        elif choice == 'b' or choice == 'B': 
            reportB() 
            break 
        else: 
            continue 

当我输入a 或b 时,它只会要求我再次“输入A 或B”。它没有发挥应有的作用。

知道这是为什么吗?

请您参考如下方法:

代码是完美的,除了多余的 else,正如评论中提到的。您输入的是 a(a + 空格)而不是简单的 a(a 没有空格)吗?问题出在您提供的输入中,而不是代码中!