Python Forum
Multiplicate several numbers
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiplicate several numbers
#2
Start with func = 1 before the loop, and then each time you calculate the new value, do func *= calculated_value to multiply it into the rolling total.

Edit:
Or, if you write your function as a function, you can use map/reduce to do the same thing much cleaner:
>>> import functools
>>> import operator
>>> def func(x):
...   return 1 + (1/(x**2))
...
>>> functools.reduce(operator.mul, map(func, range(1, 19)))
3.482783207792457
Reply


Messages In This Thread
Multiplicate several numbers - by Student0 - Oct-04-2018, 09:13 PM
RE: Multiplicate several numbers - by nilamo - Oct-04-2018, 09:34 PM
RE: Multiplicate several numbers - by Student0 - Oct-05-2018, 08:40 AM
RE: Multiplicate several numbers - by gruntfutuk - Oct-05-2018, 09:41 AM
RE: Multiplicate several numbers - by nilamo - Oct-09-2018, 05:35 PM
RE: Multiplicate several numbers - by buran - Oct-05-2018, 08:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,787 May-09-2019, 12:19 PM
Last Post: Pleiades

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020