boolean = True
print ("Enter your list of numbers. Type \"done\" when you are finished entering all your numbers ")
def collectNumbers(number):
if number is ("done"):
boolean == False #but it never actually becomes false
if boolean == True:
number = input("Enter a number ")
listofNumbers.append(number)
collectNumbers(None)
else:
print ("That is not a number. Please drink some bleach.")
collectNumbers(None)
它返回:
Enter a number 1
Enter a number 2
Enter a number 3
Enter a number 4
Enter a number done
Enter a number done
Enter a number done
Enter a number
尽管我输入“完成”,它仍然没有突破功能。 “boolean”不会变成“false”,因此函数永远不会爆发。
答案 0 :(得分:1)
if number == "done": #change is to == and strip ()
boolean = False #change == to =