educative.io

Educative

Visual factorials

hey, you have a challenge where your result variable starts a 0. It would be impossible to find factorials
without checking if n === 0. If not, please upload a solution Im very stuck on this problem and cant find a solution online.

Actually, Its relatively easy; I am providing you with a solution using Python (Programming Language)

def factorial(n):
  result = 1

  for i in range(1, n+1):
    result *= i

  return result

Try to understand it; if you can’t, feel free to express it.

Happy learning at Educative

Hey thanks, I ended up solving it. The problem I had was the result variable was set to 0 initially and
I was trying to solve the problem without changing the variable from 0 to 1. It was confusing me. I did it in JS. Thanks again for responding.