# 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

Run
```# 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.

### 6 comments on “Python Program for Permutations In Which N People Can Occupy R Seats In A Classroom”

• ankush

import math
a = math.perm(10, 6)
print(a)

• Nikita

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)

• munigala

from itertools import permutations
a=[0]*N
b=(list(permutations(a,R)
print(len(b))

• Sonal

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))

• rajat

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))

• premkumar

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))