Mr.Smithyyy - 7 months ago 44

Python Question

EDIT: I know I can import factorials but I'm doing this as an exercise

Trying to get the factor of a given number with a function in Python.

For example:

factorial(4) = 4 * 3 * 2 * 1 = 24

`def factorial(x):`

n = x

while n >= 0:

x = n * (n - 1)

n -= 1

return x

Answer

try like this: to make your code work

```
def factorial(x):
n = 1 # this will store the factorial value
while x > 0:
n = n*x
x -= 1
return n
```

you got many advice on comments follow it