Skip to content

Commit f0e99a0

Browse files
authored
Update Permutation.py
more clear
1 parent 71be942 commit f0e99a0

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

Permutation.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
1+
import math
12
print("Permutations of 'n' distinct objects taken 'r' at a time is given by:\nnPr = n!/(n-r)!, where \"!\" denotes the factorial.\n")
23

3-
44
try:
55
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)}")
6+
r = int(input("Enter the value of r (0<=r<=n): "))
7+
if n<=0 or r<0:
8+
print("'n' should be greater than 0 and 'r' must be >=0")
9+
elif r>n:
10+
print("'r' can't be greater than 'n'")
11+
else:
12+
ans = (math.factorial(n))//(math.factorial(n-r))
13+
print(f"\nPermutation of {n} distinct objects taken {r} at a time is: {ans}")
2014

2115
except Exception as e:
22-
print(f"ERROR: {e}")
16+
print(f"ERROR: {e}")

0 commit comments

Comments
 (0)