This content originally appeared on CodeSource.io and was authored by Deven
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
The post Solved – can’t multiply sequence by non-int of type ‘float’ appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Deven
Deven | Sciencx (2021-03-11T05:56:23+00:00) Solved – can’t multiply sequence by non-int of type ‘float’. Retrieved from https://www.scien.cx/2021/03/11/solved-cant-multiply-sequence-by-non-int-of-type-float/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.