Skip to content

Commit 71be942

Browse files
authored
Add files via upload
1 parent 654e93b commit 71be942

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Permutation.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
print("Permutations of 'n' distinct objects taken 'r' at a time is given by:\nnPr = n!/(n-r)!, where \"!\" denotes the factorial.\n")
2+
3+
4+
try:
5+
n = int(input("Enter the value of n (n>0): "))
6+
if n>0:
7+
r = int(input("Enter the value of r (r>=0): "))
8+
elif n<=0:
9+
print("Enter a valid input")
10+
exit()
11+
12+
def factorial(x):
13+
if x==0 or x==1:
14+
return 1
15+
else:
16+
return x*factorial(x-1)
17+
18+
ans = (factorial(n))/(factorial(n-r))
19+
print(f"\nPermutation of {n} distinct objects taken {r} at a time is: {int(ans)}")
20+
21+
except Exception as e:
22+
print(f"ERROR: {e}")

0 commit comments

Comments
 (0)