[英]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
" 我试图将float
和int
放在我的编码中,但是它仍然说“不能将序列乘以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.