2017-09-23 49 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: "))那么它会工作。

祝您有美好的一天!