We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 654e93b commit 71be942Copy full SHA for 71be942
1 file changed
Permutation.py
@@ -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