H! I’ve seen a right code for the problem on GitHub.

def product(x):
  for i in x:
  return n

As I understand this: i have a list, then I take every value from the list and multiply them by n which in this case is equal to 1. Then I return n.

So if the list is for example: [1,5,7] I will return 1,5,7 which doesn’t make much sense…

What’s the idea of the code?


it will not, how did you come to this conclusion?


1 by 1, 5 by 1. 7*1.
Probably i don’t get the logic


maybe insert some print statements then to see the logic:

def product(x):
  for i in x:
    print n
  return n

product([1, 5, 7])


Why do we need n=1 variable?


cause we need a starting value for all the multiplications.


If I multiply 1 by n, I will get n. Sorry I can’t get it:(


n = 1… n holds the value of 1. So you multiply n (which holds 1) with i (which is the iterator variable)


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.