【发布时间】:2013-08-25 17:33:36
【问题描述】:
我正在尝试执行我在 John Zelle 的 Python Programming: An Introduction to Computer Science 中找到的这个 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'
我不知道如何解决这个问题。有什么建议吗?
【问题讨论】:
-
你用的是什么版本的python?这在 2.7 中完美运行。它甚至可以在我输入真正的 jank 数字时工作......好吧,我得到它来做错误,但只有在我尝试输入一个字符串之后......当它说“输入一个介于 0 和 1 之间的数字:”时你在打字吗?
标签: python types python-3.x int