简体   繁体   English

typeerror:不能将序列乘以“int”类型的非int

[英]typeerror: can't multiply sequence by non-int of type "float

I am brand new to python (and programming in general) and I am following examples from Python Programming: An Introduction to Computer Science John M. Zelle, Ph.D. 我是python的新手(以及一般的编程),我正在学习Python编程的例子:计算机科学概论John M. Zelle,Ph.D。 Version 1.0rc2 Fall 2002 Obviously this is quite a bit out of date and I am using Python 3.3 I am typing in the exercise exactly as the book shows it (adding () around the print statements) but I keep coming up with the error. 版本1.0rc2 2002年秋季显然这已经过时了,我正在使用Python 3.3我在练习中输入完全与书中显示的一样(在打印语句周围添加())但我不断提出错误。 Here is a copy of what I input and the result when I tried to run the program. 这是我输入的内容的副本以及我尝试运行程序时的结果。 What am I doing wrong? 我究竟做错了什么?

>>> 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'
>>> 

use x=float(input ("Enter a number between 0 and 1:")) as input() returns a string in python 3k not float : 使用x=float(input ("Enter a number between 0 and 1:"))作为input()返回python 3k中的字符串而不是float

>>> def main():
...     print ("This program illustrates a chaotic function.")
...     x=float(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:.45
0.96525
0.13081550625
0.443440957341
0.962524191305
0.140678352587
0.47146301943
0.971823998886
0.106790244894
0.372005745109
0.911108135788

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:无法将序列乘以float类型的非整数 - TypeError:can't multiply sequence by non-int of type float TypeError:不能将序列乘以“float”类型的非整数? - TypeError: can't multiply sequence by non-int of type 'float'? 类型错误:不能将序列乘以浮点类型的非整数 - TypeError: Can't multiply sequence by non-int of type float TypeError:无法将序列乘以&#39;float&#39;类型的非整数 - TypeError: can't multiply sequence by non-int of type 'float' 转换为Float和Int,TypeError:无法将序列乘以&#39;float&#39;类型的非python 2.7的序列 - Converted to Float and Int, TypeError: can't multiply sequence by non-int of type 'float' Python 2.7 类型错误:不能将序列乘以“numpy.float64”类型的非整数 - 将列乘以值 - TypeError: can't multiply sequence by non-int of type 'numpy.float64' - multiply column by value TypeError:即使使用np.multiply,也不能将序列乘以&#39;float&#39;类型的非整数 - TypeError: can't multiply sequence by non-int of type 'float' even after using np.multiply “ TypeError:无法将序列乘以&#39;float&#39;类型的非整数”,即使输入已转换为float - “TypeError: can't multiply sequence by non-int of type 'float'” even though the conversion of input to float is done TypeError:无法将序列乘以&#39;float&#39;类型的非整数-转换为float后 - TypeError: can't multiply sequence by non-int of type 'float' - after converting to float TypeError:即使已经用float()解析,也不能将序列乘以&#39;float&#39;类型的非整数 - TypeError: can't multiply sequence by non-int of type 'float' even if already parsed with float()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM