Multiplying all elements in list
since “A Journey of a Thousand Miles Begins with a Single Step”
understanding how to basically reach every element in a list and using it can be a salient step in many applications.
it is not about how simple a task is .. it is all about how can I use this task to build a masterpiece out of it.
here in my simple application I take a list and multiply every element of it then return the result
here is the code snippet
#defining a function that takes a list
def multiply_all (my_list):
#defining the result as 1 so it gets multiplied by the first element
product=1
#looping over my list
for i in my_list:
#multiplying the product with the current element in the list
product=product*i
#returning the product
return product
コメント