python - 如何编写说明混沌行为的 Python 程序

标签 python python-3.x chaos

当我运行下面的程序时,它输出所有数字为 0.0。如何解决这个问题以说明困惑的行为?

# 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()

最佳答案

在获取输入的行中,您获取数字并将其设为整数。使某些东西成为整数会删除所有小数。当您输入“0.54”时,int 函数会去掉小数,只留下 0。

如果你只是执行x = float(input("输入0到1之间的数字:"))那么它就会起作用。

祝你有美好的一天!

关于python - 如何编写说明混沌行为的 Python 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46375906/

相关文章:

python - 将列表 [ ['a' ]、['b' ]] 转换为 ['a' ,'b' ]

php - 网络上的熵源

python - 重启 AKS 节点池中规模集中的 VM

python - 如何保护将分发给客户端的应用程序中的 API key

python - 如何安装这个轮子?

python - 在python中绘制带有图例的垂直线

python - 没有为 Django 迁移创建模型表

python - Pexpect 和 PyCharm - 设备的不适当的 ioctl

python re.sub 替换匹配字符串中的数字