+ 1
How to calculate thé product of numbers in list on python
Hello I want print numbers from a list and calculate their product , can you help me please. For example A=['2','3','5','9',........] The result must be 2*3*5*9 Thank you
4 Réponses
+ 4
https://code.sololearn.com/cHV9S0QMnxos/#py
The playground uses Python version 3.7.5. If they have Python 3.8.x, there is a function math.prod that you can use.
There are other ways to get the product of numbers such as using the reduce function, but I prefer the for-loop way.
Hope that helps.
+ 2
This would be another version.
You can apply that for other operations than multiplication as well.
from functools import reduce
print(reduce((lambda x, y: x*y), [3, 5, 7]))
+ 1
r1c5
Thank you
+ 1
Or this:
eval('*'.join(A))