Skip to content

Commit 68af589

Browse files
Fixes OpenGuide#59 : Add Python Program to print factorial of an entered number
Used python lambda function to recursively compute factorial.
1 parent 28278a9 commit 68af589

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#Python program to find factorial of a number recursively
2+
#This makes use of 'lambda' or anonymous functions
3+
4+
factorial = lambda x: x and x * factorial(x - 1) if x > 0 else 1
5+
6+
n = int(input('Enter a number:'))
7+
8+
print(('Factorial of '+ str(n) + ' is ' + str(factorial(n))) if not n < 0 else 'Enter a valid input')

0 commit comments

Comments
 (0)