# python can't multiply sequence by non-int of type 'float'

113 views

## Problem :

While submitting the Python program i am getting below error
python can't multiply sequence by non-int of type 'float'

## Solution :

I had faced the same issue while trying to multiple a float and a list of floats. The issue was actually due to the use of * operator on a list.

The solution is to convert the list to numpy array:

`coff = np.asarray(coff) * C`

https://github.com/ccxt/ccxt/issues/2419

## Solution:

`raw_input` returns a string . In Python, multiplying a string and a float creates no defined meaning (while multiplying a string and an integer has a signification: `"AB" * 3` is `"ABABAB"`; how much is `"L" * 3.14` ? Please do not reply `"LLL|"`). You require to parse the string to a numerical value.

### You might want to attempt:

``salesAmount = float(raw_input("Insert sale amount here\n"))``

Maybe this will support others in the future - I had the similat error while attempting to multiple a float and a list of floats. The thing is that everyone here talked about multiplying a float with a string (however here all my element were floats all along) so the problem was indeed employing the * operator on a list.

For example:

``````import math
import numpy as np
alpha = 0.2
beta=1-alpha
C = (-math.log(1-beta))/alpha

coff = [0.0,0.01,0.0,0.35,0.98,0.001,0.0]
coff *= C``````

### The error:

``````  coff *= C
TypeError: can't multiply sequence by non-int of type 'float'``````

The resolution - convert the list to numpy array:

``coff = np.asarray(coff) * C``

The issue is that salesAmount is being set to a string. In case you enter the variable in the python interpreter and stroke enter, you'll glance the value entered encompassed by quotes. For example, in case you entered 56.95 you'd view:

``````>>> sales_amount = raw_input("[Insert sale amount]: ")
[Insert sale amount]: 56.95
>>> sales_amount
'56.95'``````

You can't multiply string and float.instead of you attempt as below.it performs fine

``totalAmount = salesAmount * float(salesTax)``

To get rid of this error you require to do some changes in your q0 value which is still a string. This is originally what you're doing:

``````>>> q0 = '3'

>>> q1 = (q0 * 1.2)

Traceback (most recent call last):

File "<stdin>", line 1, in <module>

TypeError: can't multiply sequence by non-int of type 'float'``````

To solve this error you reqyire to convert the string to a number first by employing the below-mentioned way:

``````>>> q1 = (float(q0) * 1.2)

>>> q1

3.5999999999999996``````

## Related questions

204 views
Problem : I'm new to python and I've been struggling with this problem for a while. I've search google and youtube but no luck so far. I've written this in IDLE 2.6.5. If someone could tell me why I'm getting the can't multiply sequence by non-int of type float error.