To find ncR and nPr in python, you have to ask from user to enter the value of n and r and then find the value of ncR and nPr to print the result on output screen as shown in the given program.
Following python program ask from user to enter the value of n and r to find and print the value of ncR and nPr:
# Python Program - Find ncR and nPr import math; print("Enter 'x' for exit."); nval = input("Enter value of n: "); if nval == 'x': exit(); else: rval = input("Enter value of r: "); n = int(nval); r = int(rval); npr = math.factorial(n)/math.factorial(n-r); ncr = npr/math.factorial(r); print("ncR =",ncr); print("nPr =",npr);
Here is the sample run of the above Python program shows how to find ncR and nPr:
Supply the value of n say 7 and then r say 3, then press enter key to find out the value of ncR and nPr as shown in output given here:
Below is same program directly written and run on python shell:
Program Video with Compile and Run
You may also like to learn or practice the same program in other popular programming languages: