# Python GUI Find Factorial by Recursive Function

By | March 30, 2020

Topic: Find Factorial by Recursive Function Python GUI Program Find Factorial by Recursive Function Python GUI Program

```# Python GUI program Find Factorial
# of a Number by Recursion
# Input a number and show its factorial
# using a user defined recursive factorial function
# www.EasyCodeBook.com

from tkinter import *

def inputn():
n= int(entry.get())
# call recursive_factorial function
fact= recursive_factorial(n)
str1 = "Factorial of " + str(n) + " is " + str(fact)
output_label.configure(text = str1, justify=LEFT)

def recursive_factorial(n):

#  We know that Base case is factorial of 0 is 1
#  or 0! = 1
if n == 0:
return 1

# We also Know that Recursive case is : n! = n * (n-1)!
else:
return n * recursive_factorial(n-1)

main_window = Tk()
main_window.title("Perfect Python tkinter Tutorials : www.EasyCodeBook.com")
message_label = Label(text= ' Enter a number to \ncalculate its Factorial ' ,
font=( ' Verdana ' , 12))
output_label = Label(font=( ' Verdana ' , 12))
entry = Entry(font=( ' Verdana ' , 12), width=6)

calc_button = Button(text= ' Calculate Factorial ' , font=( ' Verdana ', 12),
command=inputn)

mainloop()
```

### How this program works?

As we know a Recursive function is a function that normally calls itself. the process of calling a function itself is called Recursion.

Recursion may provide a concise solution to a problem that uses loops.

The factorial of a number say 3 is 1 x 2 x 3 that is 6.

Similarly the factorial of a number n is: 1 x 2 x 3 x…x(n-1) x n

We can say that n! = n * (n-1)!

Perfect Programming Tutorials, Python , Java, C Language, C++