0

I can multiply 2 numbers without the multiplication operator with the below code:

sum(2 for i in range(5))

However, I would like to know if there's any simple way to do it for n numbers with a function call like the below:

multi(1, 2, 3, 4, 5... n)

What it's in my mind is a function that takes args 1 and 2, then does the sum(arg1 for i in range(arg2) and then does that for the remainder (arg3, arg4...)

banana_99
  • 591
  • 5
  • 15
  • The pythonic way would be to use the multiplication operator, not to invent some crude alternative. Why exactly do you want to do this? And it is not clear to me, what `multi(1, 2, 3, 4, 5)` should do. What should the expected result be? Should it be equivalent to `1 * 2 * 3 * 4 * 5` ? – MaxNoe Jul 28 '21 at 14:09
  • This is just a riddle. – banana_99 Jul 28 '21 at 14:13
  • Its work - https://pastebin.com/vadEGTTr `multi(1, 2, 3, 4, 5)` ->`120`, `multi(1, 2, 3, 4, 5, 6, 7)` ->`5040`, etc. – nigani Jul 28 '21 at 14:24
  • that's just prod. `from math import prod; prod([1, 2, 3, 4, 5])` – MaxNoe Jul 28 '21 at 16:41

0 Answers0