简体   繁体   English

TypeError:无法将序列乘以float类型的非整数

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

I tried to put the float and int inside my coding, but it still said "can't multiply sequence by non-int of type float " 我试图将floatint放在我的编码中,但是它仍然说“不能将序列乘以float类型的非整数”

PV = input("investment amout:")
r = float(input("rate:"))
n = int(input("year:"))
FV_conti = PV*(1+r)**n
import math
FV_diceret = PV * math.exp(r*n)

The issue is that PV is a string and not a float. 问题在于PV是字符串而不是浮点数。 input() is Python3 does not evaluate the input unlike in Python2 . input()Python3不评估不像在输入Python2

You need to convert it into a int / float : 您需要将其转换为int / float

PV = int(input("investment amout:"))

If you multiply a string with an int, it performs concatenation. 如果将字符串与int相乘,它将执行串联。 That is why multiplying by float does not make sense. 这就是为什么乘以浮点数没有意义。

>>> PV = "123"
>>> PV*2
'123123'
>>> PV*2.3
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'float'

暂无
暂无

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

相关问题 typeerror:不能将序列乘以“int”类型的非int - 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