Finally getting round to doing some more python.
Stuck on a little online exercise:
"Define a function prod(L) which returns the product of the elements in a
list L."

Let's say L = [1, 2, 3, 4]

I have done this so far but it's not quite working:



def prod(L):

   sum = 1
   for i in L:


      sum = sum * i


      return sum


Code seems to print the right value in REPL (i.e. 24) just a for loop
though !?!
Think I am not seeing something obvious.


Cheers,
Tahir
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to