Skip to main content

11. Program to calculate COMBINATION and PERMUTATION with simple steps

#program to calculate the combination and permutation

def factorial(number):
    c=1
    if(number==0):
        return 1
    for i in range(number,0,-1):
        c=c*i
    return c
def combination():
    print('welcome to the combination finding')
    print()
    print('''Our format is as follows:
we will ask a and b as aCb  means a combiantion b''')
    a=int(input('enter a of the combination'))
    b=int(input('enter b of the combination'))
    print('you want to find',a,'C',b)
    if(a>=b):
        
        return factorial(a)/(factorial(b)*factorial(a-b))
    else:
        print('you have written a less than b which is incorrect')
def permutation():
    print('welcome to the permutation finding')
    print('''Our format is as follows:
we will ask a and b as aPb  means a permuatation b''')
    a=int(input('enter a of the permuatation'))
    b=int(input('enter b of the permuatation'))
    print('you want to find',a,'P',b)
    if(a>=b):
        return factorial(a)/factorial(b)

print('hello this is to calculate the combination and permutation')
print('''YOU ARE REQUESTED TO FOLLOW THE FORMAT TO CALCULATE THE SAME

''')
choice=int(input('''please write 1-combination
   and       2-Permutation'''))
if(choice==1):
    result=combination()
    print('result=',int(result))
elif(choice==2):
    result=permutation()
    print('result=',int(result))
else:
    print('you have entered wrong key')


Comments

Popular posts from this blog

Programming for problem solving : Assignment no 1

 Assignment of programming for problem solving:  The questions for assignment is : The solution for the assignment is as follows :  Please subscribe the blog for more updates . Thank you! 🙏🙏

1. Python program for railway reservation system

def reserve(CLASS):     if CLASS==1:         print('welcome to the REGULAR CLASS SEAT reservation')         dest=int(input('enter your destination in km  '))         stat=int(input('enter stations in between '))         price=10*dest         amount=price+(10*stat)         print('the price for 1 seat is =',amount)         seat=int(input('enter no of seats'))         total=amount*seat         print('your final price is =',total)         print('you will have to pay',total,'INR')         return total,seat,amount     if CLASS==2:         print('welcome to the FIRST CLASS TICKET reservation')         dest=int(input('enter your destination in km  '))         stat=int(input...

BEE ASSIGNMENT

 Here is the solution of BEE ASSIGNMENT    QUESTION 1 - QUESTION 5 Question 6 to Question 10  For maths assignment : click here