Duplicate combinations in Python

Here we will write code that uses Python to calculate how many combinations there are duplicates.

Use factorial.

python



from math import factorial

print("Enter two positive integers.")
a, b= map(int, input().split())
h = (factorial(a+b-1))/(factorial(b)*factorial(a-1))
print(str(a)+"From individual things"+str(b)+"How to choose one by allowing duplication"+str(h)+"It's a street.")

You can see all the functions included in math by writing as follows.

python


import math
help(math)

Do not use factorial.

python


print("Enter two positive integers.")
a, b= map(int, input().split())
n = a + b -1
m = n
l = a-1
while  n > b+1:
    m = m * (n-1)
    n = n - 1
while l > 0:
    m = m / l
    l = l -1

print(str(a)+"From individual things"+str(b)+"How to choose one by allowing duplication"+str(m)+"It's a street.")

Recommended Posts

Duplicate combinations in Python
Find permutations / combinations in Python
Quadtree in Python --2
Python in optimization
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Factorial, permutations, (duplicate) combinations in Python / Ruby / PHP / Golang (Go)
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Enumerate duplicate combinations (C ++) → Add Python code
Duplicate prohibition processing in GAE / Python Datastore
Sorted list in Python
Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Implement Enigma in python
Daily AtCoder # 32 in Python
Daily AtCoder # 18 in Python
Singleton pattern in Python
File operations in Python
Key input in Python
Daily AtCoder # 33 in Python
Logistic distribution in Python
Daily AtCoder # 7 in Python
LU decomposition in Python
One liner in Python
Daily AtCoder # 24 in Python
case class in python