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 operator
from operator import mul
from functools import reduce
s = list(map(int, input('Enter numbers WITH SPACES: ').split(' ')))
progression_product = [];
for i in s:
progression_product.append(reduce(mul, s[0:i]))
#This loop below removes repeating results. As for progressive order multiplication of positive
#integers. It's impossible to have a repeating result.(excluding multiple 1's and 0)
for ss in progression_product:
if progression_product.count(ss) > 1:
progression_product.remove(ss)
print(progression_product)
- Notice that the output skips the result for 13 below. But finishes correctly for the overall product of all integers at the end of the listed output
Enter numbers WITH SPACES: 12 2 3 4 13 133
[24, 72, 288, 497952]
> 12*2*3*4*13
>3744
Question
Is there any way to fix this bug? Why would python skip the result at 13? And, how do I fix it?
for i in s:
It most definitely does not do what you think it does. – Hypotaxis