Formula for factorials, don't get it
Hi if you look below, here's some code for calculating a factorial. Ie. the factorial of 5 is 5! = 5*4*3*2*1 the factorial of 0 is 0!=1 After going round in circles I picked the code below off the internet. But I am having difficulty with it. The code creates a function called factorial and in its definition calls on itself It's a recursive process I know... but how can a function be defined by itself? Anyone can explain? Thanks! ____________ """Here we are setting up a prompt to ask for number going in""" number=int(input("The factorial for ")) """ This is creating a function based on variable i""" def factorial(i): if i==0: return 1 else: return i * factorial(i-1) print ( number, "is", factorial(number))