我正在尝试执行我在Python Programming: An Introduction to Computer Science by John Zelle 中找到的这个示例 Python 脚本:
# File: chaos.py
# A simple program illustrating chatic behavior
def main():
print("This program illustrates a chaotic function")
x = input("Enter a number between 0 and 1: ")
for i in range(10):
x = 3.9 * x * (1 - x)
print(x)
main()
...但由于某种原因,我不断收到此错误:
Traceback (most recent call last):
File "C:\...\chaos.py", line 11, in <module>
main()
File "C:\...\chaos.py", line 8, in main
x = 3.9 * x * (1 - x)
TypeError: can't multiply sequence by non-int of type 'float'
我不知道如何解决这个问题。有什么建议么?