03-06-2013, 01:32 AM

To find the factorial of a number you need to know what a factorial is..I assume you do, but if you don't, here:

A factorial is a number multiplied by one less than itself until it reaches 0 (exclusive)...

So a factorial of 4 is : 4*3, 4*2, 4*1 = 24

Here's how to do that in Python using a ternary expression making it super short:

A factorial is a number multiplied by one less than itself until it reaches 0 (exclusive)...

So a factorial of 4 is : 4*3, 4*2, 4*1 = 24

Here's how to do that in Python using a ternary expression making it super short:

Code:

`def factorial(n):`

return 1 if n == 0 else n*factorial(n-1)

print factorial(4)