Skip to content Skip to sidebar Skip to footer

How To Multiply Each Integer "one By One" And Display Result "in Progressive Order" Until All Integers Multiplied Leads To The Overall Product

Recently, I've tried creating a for loop that multiplies each integer in the list and returns each sequential product until the overall product of all integers is given. import

Solution 1:

You are iterating over the elements of s, not the indexes. Print the list before removing the duplicates, it will be:

[497952, 24, 72, 288, 497952, 497952]
# Whicharetheproductsof:
[s[0:12], s[0:2], s[0:3], s[0:4], s[0:13], s[0:133]]

Replace the first loop by a index loop, either by range(len(s)) or by enumerate(s):

# Either this:
progression_product = [];
for i in range(len(s)):
      progression_product.append(reduce(mul, s[0:i]))

# Or this:
progression_product = [];
for i, v in enumerate(s):
      progression_product.append(reduce(mul, s[0:i]))

Post a Comment for "How To Multiply Each Integer "one By One" And Display Result "in Progressive Order" Until All Integers Multiplied Leads To The Overall Product"