write a recursive program to find factorial of a number using pydatalog

Hi guys, in this article you will learn a Python program related to finding the  factorial of a function using the recursive method that is in data log.

pyDataLog is said to be a powerful syntactical language  derived from python as per the website.

https://sites.google.com/site/pydatalog/Online-datalog-tutorial

The above website also mentions the  program to  calculate the  factorial of a number using pyDataLog



write a recursive program to find factorial of a number using pydatalog





write a recursive program to find factorial of a number using pydatalog

In order to execute this Python program you should have installed the pyDataLog module and imported it as shown below.

Then using the building function create the terms named as factorial and N.  

from pyDatalog import pyDatalog

pyDatalog.create_terms('factorial, N')



Now define the factorial function recursive method,  factorial of n is multiplied by factorial of N - 1.  if the value of n is 1  then the factorial is equal to 1.

factorial[N] = N * factorial[N-1]
factorial[1] = 1



Now using the input function call as the user to enter an integer number and store it in X,  call the factorial function by using the print function call and directly print it.

X = int(input("Enter a Integer Number : "))
print(factorial[X]==N)




complete program
=========================

from pyDatalog import pyDatalog

pyDatalog.create_terms('factorial, N')

factorial[N] = N * factorial[N-1]
factorial[1] = 1

X = int(input('Please enter your name : '))

print(factorial[X]==N)





Output
==============
Please enter your name : 34
N                                      
---------------------------------------
295232799039604140847618609643520000000




Conclusion
====================
The above program uses the pyDataLog module. You should be having pre pre-installed module on your computer.

Execute the above Python program and comment on below if you have any queries

Post a Comment

0 Comments