Tuesday, 28 May 2019

Find ncr and npr

Ex3: Find ncr and npr:
"""
c= no of distinct combinations
n=total no of objects in the set
r=no of choosing objects from the set
5c2=n!/(n-r)!
Input: Two positive integers as the total no of objects and sample size
Output:A positive integer as the permutation or permutation of 'n' objects
taken at 'r' at a time
"""
import math
#n,r=(int(x)for x in input("enter 2 numbers:").split())
n=int(input("enter n value: ="))
r=int(input("enter r value: ="))
if n>=r:
    print("ncr=",math.factorial(n)/(math.factorial(r)*math.factorial(n-r)))
    print("npr=",math.factorial(n)/(math.factorial(n-r)))
else:
    print("value of n can not be <r")

"""enter n value: =5
enter r value: =2
ncr= 10.0
npr= 20.0
>>>
===================== RESTART: F:\Programs\input\ncr.py =====================
enter n value: =2
enter r value: =5
value of n can not be <r
>>> """

No comments:

Post a Comment

Files with Exception handling

#Ask the user to take two input integer values var a,b try:     a=int(input("enter any integer value:"))     b=int(input(&qu...