C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

How to multiply sequence by non-int of type 'float'?

By : Pam Serfass
Date : November 21 2020, 07:38 AM
it fixes the issue Multiplying python lists by an integer gives you a multiple of the list.
code :
``````>>> a = [1]
>>> a * 3
[1,1,1]
``````
``````>>> import numpy as np
>>> a = [[1,1],[1,1]]
>>> a = np.array(a)
>>> a * 0.1
array([[ 0.1,  0.1],
[ 0.1,  0.1]])
``````

Share :

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

By : master_dude
Date : March 29 2020, 07:55 AM
around this issue I've been asked to write a simulator, the end goal being to see how much ink ends up on a cylinder at the end of a chain of maybe 15 or so rollers. I'm currently trying to set-up a dictionary which defines the rollers. From this i wanted to write a function which will take user input, 'roller_diameter', find the ratio of the given diameter to a fixed diameter and convert this into an integer number of 'segments'. I'm not a programmer (i'm learning Python[2.7] using internet resources) and am struggling with the TypeError: can't multipy sequence by non-int type 'float' I'm sure this is a trivial issue and I have looked at the related answers but have been unable to understand what specifically I'm doing wrong...Any suggestions would be greatly appreciated, here's the code (with only a few 'rollers'), please don't laugh... , In this line:
code :
``````R['segments'] = int(round(rollers[3]['segments']*roller_diameter/plate_diameter))
``````
``````TypeError: can't multiply sequence by non-int of type 'float'
``````
``````rollers[3] = ['top_seg': 0, 'roller_diameter': [], 'segments': [], 'material': Rubber, 'direction': CW, 'ink': []}
``````
``````R = rollers[i]
``````
``````    R = rollers[i]
NameError: name 'i' is not defined
``````
``````def roller_data():
global roller_diameter
print i
roller_diameter = float(raw_input("Enter the roller diameter" + str(i) + ': '))
``````
``````def read_diameter(i):
return float(raw_input("Enter the roller diameter # {}: ".format(i)))
``````
``````rollers[i]['roller_diameter'] = read_diameter(i)
``````

TypeError: can't multiply sequence by non-int of type 'float' even if already parsed with float()

By : Yøung Jøseph
Date : March 29 2020, 07:55 AM
it helps some times You are interpolating into the string first, then multiplying the result:
code :
``````>>> y = 2.5
>>> "Is %f pounds\n" % y*2.205
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'float'
``````
``````>>> "Is %f pounds\n" % (y*2.205)
'Is 5.512500 pounds\n'
``````
``````print "Is %f kilos\n" % (y/2.205)
``````
``````print "Is {:f} pounds\n".format(y * 2.205)
``````
``````print "Is {:f} kilos\n".format(y / 2.205)
``````

Converted to Float and Int, TypeError: can't multiply sequence by non-int of type 'float' Python 2.7

By : Alferd Jhorden
Date : March 29 2020, 07:55 AM
I hope this helps you . I am trying to open a CSV file, iterate over its row's and convert the final part of row to a new number created by multiplying the existing value with a floating point number. , In your code, neither of
code :
``````    if isinstance(row[8], float):
row[8] = float(row[8])
if isinstance(row[8], int):
row[8] = int(row[8])
``````

Cant multiply sequence by non-int of type 'float'

By : pedro
Date : March 29 2020, 07:55 AM
To fix this issue raw_input() returns a string. You can't multiply a string with a number, so you need to convert the number string to an actual number format first, for instance with the float() function:
code :
``````number = raw_input()
``````
``````>>> type(number)
<type 'str'>
>>> type(float(number))
<type 'float'>``````

TypeError: can't multiply sequence by non-int of type 'float' - after converting to float

By : Kervin Yap Bardilas
Date : March 29 2020, 07:55 AM
To fix the issue you can do From your code I assume that you want entry_validation to return a float, but it is actually returning the string you provide when calling it.
For example, in:
code :
``````entry_exam1 = entry_validation ('Exam 1')
``````
``````def entry_validation (assignment) :
entry = -1

while entry == -1:
entry = input ('What was your final score for ' + assignment + '? ')

if entry == '':
entry = -1
print ('ERROR: You cannot leave this field blank. Please try again.')

else:
# Let's handle possible exceptions when the input cannot be converted
try:
entry = float (entry)
if entry < 0 or entry > 100:
entry = -1
print ('ERROR: You score must be between 0 and 100. Please try again.')
else:
return entry
except ValueError:
entry = -1
print("ERROR: Must be a float")
``````