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"

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)

1 answer

  • answered 2018-07-11 06:29 RohithS98

    The issue is that PV is a string and not a float. input() is Python3 does not evaluate the input unlike in Python2.

    You need to convert it into a int/float:

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

    If you multiply a string with an int, it performs concatenation. 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'