2017-02-06 57 views
-2
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」,因此函數永遠不會發生。

+4

賦值是用'='而不是'=='來完成的......此外,您應該**不使用'is',而是使用==來比較字符串**,因爲不是所有字符串被攔截。 –

+2

您也可以使用'=='而不是'is'來進行字符串比較。 –

回答

1
if number == "done": #change is to == and strip() 
    boolean = False #change == to = 
+2

並將'is'更改爲== == ... –