Python TypeError:无法将序列与类型为float的非int相乘

Python TypeError:无法将序列与类型为float的非int相乘,python,typeerror,Python,Typeerror,我试图在我的代码中加入float和int,但它仍然表示不能将序列乘以float类型的非int 问题在于PV是一个字符串而不是一个浮点。与中不同,输入是不计算输入的 您需要将其转换为int/float: 如果将字符串与int相乘,它将执行串联。这就是为什么用浮点数相乘没有意义 >>> PV = "123" >>> PV*2 '123123' >>> PV*2.3 Traceback (most recent call last): File

我试图在我的代码中加入float和int,但它仍然表示不能将序列乘以float类型的非int


问题在于PV是一个字符串而不是一个浮点。与中不同,输入是不计算输入的

您需要将其转换为int/float:

如果将字符串与int相乘,它将执行串联。这就是为什么用浮点数相乘没有意义

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

这是哪种语言?如果是python,那么试试PV=intinputinvestment amout:这是python。谢谢!我找到了。你找到了吗?或者@RohithS98的评论对你有帮助吗?在后一种情况下,请你们两人回答并接受。
PV = int(input("investment amout:"))
>>> 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'