From b9734c7b927229955b553f152c72bd77bd8264ab Mon Sep 17 00:00:00 2001 From: Yashwanth-kumar-s Date: Wed, 8 Mar 2023 17:01:30 +0530 Subject: [PATCH] Create adding12.py --- adding12.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 adding12.py 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)