0
Is it possible to multiply numbers in two range lists?
#i wanted to make like lists with given numbers in range and multiply them together. Thank you for your help in advance import math my_range=range(0,9) my_range1=range(0,9) main_range = my_range*my_range1 result = math.prod(math_mult) print=(result)
5 Antworten
+ 1
Do you mean like this?
a = range(0,9)
b = range(0,9)
for m in a:
for x in b:
if a.index(m) == b.index(x):
print (a[m] * b[x])
+ 2
What sort of output were you expecting from multiplication of the two ranges? is there additional rules applied for this operation? do the ranges always span in equal length?
At least provide an example for the result of multiplication
+ 2
Idk if there was a way or method to literally multiply ranges - like they were numbers.
However we can, by using loop or comprehension, generate a list whose contents was a multiplication of numbers within two ranges.
range1 = range( 1, 6 ) # 1 ~ 5
range2 = range( 6, 11 ) # 6 ~ 10
result = [ n[ 0 ] * n[ 1 ] for n in zip( range1, range2 ) ]
print( result ) # multiply number from each range
+ 1
I'm not expecting any specific result, just asked if there is such method that allows 2 ranges to be multiplied
+ 1
Thank you all for help. Friendly greetings.