-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4. Q7.py
More file actions
31 lines (22 loc) · 731 Bytes
/
4. Q7.py
File metadata and controls
31 lines (22 loc) · 731 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Print nCr and nPr.
# Function to calculate factorial using a for loop
def factorial(num):
fact = 1
for i in range(1, num + 1):
fact *= i
return fact
# Function to calculate nCr (Combinations)
def nCr(n, r):
return factorial(n) // (factorial(r) * factorial(n - r))
# Function to calculate nPr (Permutations)
def nPr(n, r):
return factorial(n) // factorial(n - r)
# Taking inputs from the user
n = int(input("Enter value of n: "))
r = int(input("Enter value of r: "))
# Calculating nCr and nPr
combinations = nCr(n, r)
permutations = nPr(n, r)
# Displaying the results
print(f"nCr (Combinations) = {combinations}")
print(f"nPr (Permutations) = {permutations}")