# [Solved] Python can’t Multiply Sequence by non-int of type ‘float’

The TypeError: can’t multiply sequence by non-int of type ‘float’ occurs if we use the multiply operator between a string and float value.

In this tutorial, we will learn what exactly TypeError: can’t multiply sequence by non-int of type ‘float’ error means and how to resolve this TypeError in your program with examples.

## TypeError: can’t multiply sequence by non-int of type ‘float’

Python is one of the best programming languages because of its features and simplicity. One such fantastic feature in Python is we can multiply strings with numbers.

### Multiplying string with an integer

Let’s take an example to demonstrate multiplying string with numbers.

The other popular programming languages will never let you to multiple strings and integers. However, we can perform a multiplication between string and integer in Python. After the multiplication, the string is repeated for n times, as shown below.

``````text = "ItsMyCode"
n = 3
print(text*n)
``````

Output

``ItsMyCodeItsMyCodeItsMyCode``

Here the string “`ItsMyCode`” is repeated multiplied by three and repeated three times in the output.

`Note: We cannot multiply string with another string, if we do Python interpreter will throw TypeError: can't multiply sequence by non-int of type 'str'. `

If we try to multiply the string with non-int, let’s say, a floating-point value, then the Python interpreter will throw TypeError: can’t multiply sequence by non-int of type ‘float’.

### Multiplying string with a floating-point

You cannot multiply a string with a non-integer value in Python. Hence if we multiply a string with a floating-point value, we get the error can’t multiply sequence by non-int of type ‘float’.

Let’s take an example to demonstrate multiplying string with a floating-point value.

``````text = "ItsMyCode"

# floating-point value
n = 3.0
print(text*n)
``````

Output

``````Traceback (most recent call last):
File "C:\Personal\IJS\Code\program.py", line 3, in <module>
print(text*n)
TypeError: can't multiply sequence by non-int of type 'float'``````

Even though the number entered here is equal to the integer value 3, the Python interpreter will still consider it a floating-point value and raise a TypeError.

The simplest way to resolve this issue is by converting the floating-point to an integer and then multiplying it with a string, as shown below.

``````text = "ItsMyCode"

# convert floating-point value to int
n = int(3.0)
print(text*n)``````

Output

``ItsMyCodeItsMyCodeItsMyCode``

## Solution TypeError: can’t multiply sequence by non-int of type ‘float’

Now we know that TypeError: can’t multiply sequence by non-int of type float is caused by multiplying a string with a floating-point number. Let us see how we can resolve this error with an example.

Usually, we get this error when we receive input from the user, and it will be of a string format. Consider we have to provide a discount based on the total order value to users.

In the below program, we accept the order value as a string, and we have a fixed discount of 5% on the total order value.

When we multiply the order_value in string format with a discount value in float, we get an error “can’t multiply sequence by non-int of type float”.

``````order_value = input("Enter the order value ")
discount = 0.05

total_cost = order_value - (order_value * discount)
print(round(total_cost, 2))
``````

Output

``````Enter the order value 200
Traceback (most recent call last):
File "C:\Personal\IJS\Code\main.py", line 4, in <module>
total_cost = order_value - (order_value * discount)
TypeError: can't multiply sequence by non-int of type 'float'``````

The best way to resolve this error is to convert the user input string to a floating-point using the `float()` method.

This allows us to multiply the order_value and discount because both are floating-point numbers.

``````order_value = float(input("Enter the order value "))
discount = 0.05

total_cost = order_value - (order_value * discount)
print(round(total_cost, 2))
``````

Output

``````Enter the order value 200
190.0``````

## Conclusion

We cannot multiply strings with floating-point numbers. We cannot perform this because multiplying strings with integers will create a repetitive sequence of strings.

The same is not possible using the floating-point number as it would result in multiplying a string with decimal point values.

In order to solve this issue, TypeError: can’t multiply sequence by non-int of type ‘float’ ensure that either you are performing a multiplication between string and integer or alternatively you can convert all the string values into a floating-point number before performing any calculations.

Subscribe to get notified of the latest articles. We will never spam you. Be a part of our ever-growing community.

##### You May Also Like ## How to enable CORS on Django REST Framework?

If we are building an API layer using the Django REST framework and accessing these APIs in the front-end application we need to enable the CORS on Django Rest Framework… ## Python type()

Table of Contents Hide type() Syntaxtype() Parameterstype() Return ValueDifference between type() function and isinstance() functionExample of isinstance() method in PythonExample 1: Finding the type of a Python objectExample 2: type()… ## ValueError: too many values to unpack (expected 2)

Table of Contents Hide What is Unpacking in Python?Unpacking using List in PythonUnpacking list using underscoreUnpacking list using an asteriskWhat is ValueError: too many values to unpack (expected 2)?Scenario 1:… ## Remove Character From String Python

Table of Contents Hide Python Remove a Character from a StringPython Remove Character from String using replace()Remove a single character from a stringRemove all occurrences of a character from a… ## Python Split list into chunks

Table of Contents Hide Python Split list into chunksMethod 1: Using a For-LoopMethod 2: Using the List Comprehension MethodMethod 3: Using the itertools MethodMethod 4: Using the NumPy MethodMethod 5:… ## How to Fix in Python ValueError: Trailing data?

In Python ValueError: Trailing data occurs when you try to load the JSON data or file into pandas DataFrame, and the data is written in lines separated with newline characters…