Python Program for Permutations In Which N People Can Occupy R Seats In A Classroom
Which n people can occupy r seats in a classroom in Python
Here, we will discuss program for Permutations In Which N People Can Occupy R Seats in python .In this python program, we will be defining the number of ways in which N number of students can occupy R number of seats. Take an example Ten friends enter the classroom late and all the seats are occupied by toppers of the college and now only Six seats are available so in how many ways are those Ten friends will occupy Six seats although 4 students have to leave the classroom. We will use math library for factorial function in building of this program.
Problem Statement :
In a classroom some of the seats are already occupied by students and only a few seats are available in the classroom. The available seats are assumed as r and n number of students are looking for the seat. We need to find in how many different permutations n number of students can sit on r number of chairs.
Algorithm
- Input number of students in n
- Input number of seats in r
- Use permutation formula { factorial(n) / factorial(n-r) }
- Print Output
Python code
# Permutations in which n people can occupy r seats # function for factorial def factorial(num): fact = 1 for i in range(num, 1, -1): fact *= i return fact # main program # user input n = int(input("Enter number of people: ")) r = int(input("Enter number of seats: ")) # finding all possible arrangements of n people on r seats # by using formula of permutation p = factorial(n) // factorial(n - r) # printing output print("Total possible arrangements:", p)
Output
Enter number of people: 10 Enter number of seats: 6 Total possible arrangements: 151200
For similar question click on given button.
Prime Course Trailer
Related Banners
Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription
Login/Signup to comment
n=int(input(“Enter number of students : “))
r=int(input(“Enter number of seats : “))
def facts(s):
if s==0:
return 1
else:
return s*facts(s-1)
print(facts(n)/facts(n-r))
def fact(n):
factorial=1
for i in range(1,n+1):
factorial=factorial*i
i=i+1
return factorial
n=10
r=6
res=fact(n)//fact(n-r)
print(res)
a=int(input())#5
b=int(input())#3
fact=1
fac=1
for i in range(2,a+1):
fact=fact*i
z=fact
print(z)
fac=1
for j in range(2,b+1):
fac=fac*j
y=fac
print(y)
c=a-b
fa=1
for k in range(2,c+1):
fa=fa*k
l=fa
print(fa)
x=y*c
print(x)
permutation=z//l
print(permutation)
Join our Discord channel if you have any technical query
def factorial(n):
fact=1
for i in range(n,1,-1):
fact*=i
return fact
n=int(input())
r=int(input())
arrange=(factorial(n)//factorial(n-r))
print(“arrangement is”,arrange,’ways’)
factorial(n)
import math
a = math.perm(10, 6)
print(a)
n = int(input(“Enter the number of students: “))
r = int(input(“Enter the number of seats: “))
a = n – r
def calc_fact(number):
fact = 1
while number > 0:
fact = fact * number
number -= 1
return fact
t_o_w = int(calc_fact(n) / calc_fact(a))
print(“Total number of ways are: “, t_o_w)
from itertools import permutations
a=[0]*N
b=(list(permutations(a,R)
print(len(b))
num=int(input(“Enter the number of students “))
r=int(input(“Enter the number of seats “))
fact1,fact2=1,1
for i in range(1,num+1):
fact1*=i
for j in range(1,(num-r)+1):
fact2*=j
w=fact1//fact2
print(“{} people can occupy {} seats in {} ways”.format(num,r,w))
Just 4 LINES.
import math
n = int(input(“Enter the number of Students:”))
m = int(input(“Enter the number of Seats:”))
print(math.perm(n, m))
Python program to calculate number of ways in which N people can occupy R seats
import math
n=int(input())
r=int(input())
print(math.perm(n,r))