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

217 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

16 views
Problem: While strings can be multiplied by integers to create a repeating sequence, strings cannot be multiplied by floats. Otherwise, Java returns an error.I was going to talk about the &ldquo;typeerror: can t multiply sequence by non-int of type &lsquo;float&rsquo;&rdquo; error and why it is raised. We&rsquo;ll walk through an example scenario with this error present so that how can i solve it.
218 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.
9 views
Problem: Hi! I am new to the world of programming. I am trying to multiply two numbers that will be entered by the user. I wrote the following program: number1 = input("Enter first number: ") number2 = input("Enter second number: ") print(number1," * ",number2," = ", ... = ",number1*number2) TypeError: can't multiply sequence by non-int of type 'str' I have no idea what I am doing wrong. Any help?
8 views
Problem: Hi there! I have been working in Python for a while. I am trying to run following program: value = 4.0 for val in value: number = float(input("Enter a number: ")) if number == 0: print("Zero") elif number > 0: print("Positive") elif ... understand what is causing this error. I want to take input from user unless val becomes 4. Could anyone from here please help me solve this error?
44 views
Problem: Hi there! I am new to the world of Python, and I am just trying new things in programming. I learned somewhere about the split() method and tried the following program: number = 43.42 another = number.split() print(another) When I executed this program ... numbers before and after the decimal point. I have no idea what caused this error. Can anyone here help me solve the problem, please?
3 views
Problem: I am creating a program that reads a file and if the first line of the file is not blank, it reads the next four lines. Calculations are performed on those lines and then the next line is read. If that line is not empty it continues. However, I am getting this error: ... with base 10: ''. It is reading the first line but can't convert it to an integer. What can I do to fix this problem?