Python | sympy.partition() method
Last Updated :
26 Jul, 2019
With the help of
sympy.partition() method, we can find
Partition number in SymPy.
partition(n) -
The Partition numbers are a sequence of integers
pn that represent the number of distinct ways of representing
n as a sum of natural numbers (with order irrelevant). The generating function for
pn is given by –
.
Syntax: partition(n)
Parameter:
n – It denotes the number upto which partition number is to be calculated.
Returns: Returns the nth partition number.
Example #1:
from sympy import *
n = 7
print ( "Value of n = {}" . format (n))
nth_partition = partition(n)
print ( "Value of nth partition number : {}" . format (nth_partition))
|
Output:
Value of n = 7
Value of nth partition number : 15
Example #2:
from sympy import *
n = 10
print ( "Value of n = {}" . format (n))
n_partition = [partition(x) for x in range ( 1 , 11 )]
print ( "N partition number are : {}" . format (n_partition))
|
Output:
Value of n = 10
N partition number are : [1, 2, 3, 5, 7, 11, 15, 22, 30, 42]
Share your thoughts in the comments
Please Login to comment...