Entering edit mode
5.3 years ago
macadamopetrus
•
0
Dear all, I wrote a code to multiply all the elements from the lists. It goes something like this:
for i in list(combinations):
new_value = list()
result = 1
for answers in list(combinations):
result = result * answers
return result
print(new_value)
But the problem is that this function doesn't work. But what does work is:
def multiplyList(myList):
result = 1
for z in myList:
result = result * z
return result
combinations = [4, 2, 2, 6]
print(multiplyList(combinations))
96
This gives the result as expected 96. But then the problem is that I have to copy past the list of my combinations in the code and get the answer. Does anyone know how to automatically read the list and multiply all the numbers in the combination list?