Pages

Python: Return None

While i was typing a program which calculates the factoriel, i had an 'None'. I searched stackoverflow for the  understand what is going on and i discovered what was wrong.

The related link is:

http://stackoverflow.com/questions/5101402/python-creating-a-table-what-does-none-mean/13878975#13878975

If it happends for you, use return instead of print for your function. And then assign it to a variable and print this variable. Otherwise you will get 'None' when the program prints.


def factoriel(n): 
    i = 1 
    calculation = float(n)                  
    while i < n:
        calculation = calculation * i
        i += 1 
        return calculation           

x = factoriel(5) 

print x, type(x)