error solved

Solved – can’t multiply sequence by non-int of type ‘float’


In this article, you will learn how to solve can’t multiply sequence by non-int of type ‘float’ error in Python.

Let’s look at a code example that produces the same error.

spend = input("How much did you spend? ")
discount = 0.22
money_left = spend - (spend * discount)
print(round(money_left, 2))

output

How much did you spend? 100
Traceback (most recent call last):
  File "<string>", line 3, in <module>
TypeError: can't multiply sequence by non-int of type 'float'

In order to solve solve can’t multiply sequence by non-int of type ‘float’ error in Python we use the We use the float() method like in the code snippet below:

spend = float(input("How much did you spend? "))
discount = 0.22
money_left = spend - (spend * discount)
print(round(money_left, 2))

Output

How much did you spend? 100
78.0

Share on social media

//