从while循环中退出-python

问题描述 投票:-1回答:1

我不明白为什么我不能从简单循环中走出来。你可以帮帮我吗?

这里是代码:

a = 1

#tip checking loop
while a != 0:
    # tip value question - not defined as integer to be able to get empty value
    b = input("Give me the tip quantinty which you gave to Johnnemy 'hundred' Collins :")
    # loop checking if value has been given
    if b:
        #if b is given - checking how much it is
        if int(b) >= 100:
            print("\nJohnny says : SUPER!")
        elif int(b) < 100:
            print("\nJohnny says : Next time I spit in your soup")
    elif b == '0':
        a = 0

    else:
        print("You need to tell how much you tipped")

print("\n\nZERO ? this is the end of this conversation")
python loops while-loop
1个回答
0
投票

您可以在要停止循环以便退出循环的每个循环分支的末尾t break out of the loop because. actually, there is no break. You need to putbreak`命令。

© www.soinside.com 2019 - 2024. All rights reserved.