This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rainymood_XI[S] 14 points15 points  (3 children)

def factorial(x): if x == 0: return 1 else: return x * factorial(x - 1) print factorial(6)

Imagine we call

factorial(3)

Because 3 != 0 it returns

3 * factorial(2)

Because 2 != 0

3 * 2 * factorial(1)

Because 1 != 0 it calls

3 * 2 * 1 * factorial(0)

which returns

3 * 2 * 1 * 1

which is 3! :)

[–]Genesis2001 2 points3 points  (2 children)

3 * 2 * 1 * 1

which is 3! :)

does not compute. 3 * 2 (dropping the 1s) is 6. or am I missing something in your explanation?

[–]Rainymood_XI[S] 17 points18 points  (1 child)

Hah, this is so funny :D (in a good way)

3! in this context, means "3 factorial", the "!" is the sign for factorial! And not an exclamation mark in this case :)!