当我希望它结束​​时,Python程序继续打印“退出”

时间:2014-01-18 02:45:21

标签: python syntax

以下程序不会停止打印“退出”

myvar = str("")
while myvar.lower() != "quit":
    myvar = raw_input()
    print myvar 

谢谢

2 个答案:

答案 0 :(得分:3)

我会使用while True:循环,然后在myvar.lower() == "quit"

时将其分解
# Loop continuously
while True:   
    # Get the input                  
    myvar = raw_input()
    # When converted to lowercase, if the input equals "quit"...
    if myvar.lower() == "quit":
        # ...break the loop
        break
    # If we get here, then myvar.lower() != "quit"
    # So, print the input
    print myvar 

答案 1 :(得分:2)

只需更改订单。

myvar = raw_input()
while myvar.lower() != "quit":
    print myvar 
    myvar = raw_input()