diff --git a/adding12.py b/adding12.py new file mode 100644 index 0000000..0fcac4c --- /dev/null +++ b/adding12.py @@ -0,0 +1,23 @@ +# Python program to find the factorial of a number provided by the user +# using recursion + +def factorial(x): + """This is a recursive function + to find the factorial of an integer""" + + if x == 1: + return 1 + else: + # recursive call to the function + return (x * factorial(x-1)) + + +# change the value for a different result +num = 7 + +# to take input from the user +# num = int(input("Enter a number: ")) + +# call the factorial function +result = factorial(num) +print("The factorial of", num, "is", result)