2017-09-23 46 views
1

當我運行下面的程序時,它輸出所有的數字爲0.0。如何解決這個問題來說明混沌行爲?如何編寫說明混沌行爲的Python程序

# A simple program illustrating chaotic behaviour 

def main(): 
    print ("This program illustrates a chaotic function") 
    x = int (float(input("Enter a number between 0 and 1: "))) 
    for i in range(10): 
     x = 3.9 * x * (1-x) 
     print (x) 

main() 
+1

Python的'int()'層數,所以0到1之間的每個數字都舍入爲0。 – wrkyle

回答

2

在你得到輸入的行中,你取這個數字並把它作爲一個整數。使一個整數的東西刪除所有的小數。當你輸入'0.54'時,那麼int函數將小數點取下,只剩下0.

如果你只是做x = float(input("Enter a number between 0 and 1: "))那麼它會工作。

祝您有美好的一天!