codescracker


python

Python Program to Find ncR and nPr



« Previous Program Next Program »


Find ncR and nPr in Python

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.

Python Programming Code to Find ncR and nPr

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
while True:
	print("Enter 'x' for exit.")
	nval = input("Enter value of n: ")
	rval = input("Enter value of r: ")
	if nval == 'x':
		break
	else:
		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)
		print("\n")

Here is the sample run of the above Python program shows how to find ncR and nPr:

python find ncR and nPr

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »




Tools
Calculator

Quick Links
Signup - Login - Give Online Test