我对python(以及一般的编程)是全新的,下面是 Python编程: 计算机科学导论 John M.Zelle博士。 版本1.0rc2 2002年秋季 显然这有点过时了,我使用的是python3.3 我在练习中键入的内容与书中所示的完全一样(在print语句周围加上()),但是我一直遇到错误。这是我输入的内容和运行程序时的结果的副本。我做错什么了?在
>>> 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()
This program illustrates a chaotic function.
Enter a number between 0 and 1:1
Traceback (most recent call last):
File "<pyshell#12>", line 1, in <module>
main()
File "<pyshell#11>", line 5, in main
x= 3.9*x*(1-x)
TypeError: can't multiply sequence by non-int of type 'float'
>>>
使用
x=float(input ("Enter a number between 0 and 1:"))
作为input()
返回python3k中的字符串而不是float
:相关问题 更多 >
编程相关推荐