Recursive function won't compile

Gary Herron gherron at islandtraining.com
Wed Apr 2 17:00:26 EDT 2008


bc1891 at googlemail.com wrote:
> #include <stdio.h>
> #include <stdlib.h>
>
> def RecursiveFact(n):
>     if(n>1):
>         return n*RecursiveFact(n-1)
>     else:
>         return 1
>
> fact = RecursiveFact(31)
> print fact
>
> fact = "End of program"
> print fact
>
>
> ......but yet it still gives the right answer. How is this possible?
>   

Why not?  What did you expect?

Hint:

The first two lines are comments to Python -- so are ignored.

The last two lines just print a string -- no problem there.

The recursive calculation is standard -- the extra set of parenthesis in 
the if don't cause any problem.

So again please: Why are you surprised?

Gary Herron






More information about the Python-list mailing list