File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import math
12print ("Permutations of 'n' distinct objects taken 'r' at a time is given by:\n nPr = n!/(n-r)!, where \" !\" denotes the factorial.\n " )
23
3-
44try :
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"\n Permutation 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"\n Permutation of { n } distinct objects taken { r } at a time is: { ans } " )
2014
2115except Exception as e :
22- print (f"ERROR: { e } " )
16+ print (f"ERROR: { e } " )
You can’t perform that action at this time.
0 commit comments