# Python | sympy.tribonacci() method

• Last Updated : 14 Jul, 2019

With the help of sympy.tribonacci() method, we can find Tribonacci number and Tribonacci polynomial in SymPy.

` Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  `

`To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course`

## `tribonacci(n) -`

The Tribonacci numbers are the integer sequence defined by the initial terms , , and the three-term recurrence relation .

Syntax: tribonacci(n)

Parameter:
n – It denotes the number upto which Tribonacci number is to be calculated.

Returns: Returns the nth Tribonacci number.

Example #1:

 `# import sympy ``from` `sympy ``import` `*` ` ` `n ``=` `7``print``(``"Value of n = {}"``.``format``(n))``  ` `# Use sympy.tribonacci() method ``nth_tribonacci ``=` `tribonacci(n)  ``     ` `print``(``"Value of nth tribonacci number : {}"``.``format``(nth_tribonacci))  `

Output:

```Value of n = 7
Value of nth tribonacci number : 24
```

## `tribonacci(n, k) -`

The Tribonacci polynomials are defined by , , and for . For all positive integers , .

Syntax: tribonacci(n, k)

Parameter:
n – It denotes the nth Tribonacci polynomial.
k – It denotes the variable in the Tribonacci polynomial.

Returns: Returns the nth Tribonacci polynomial in k, Tn(k)

Example #2:

 `# import sympy ``from` `sympy ``import` `*` ` ` `n ``=` `5``k ``=` `symbols(``'x'``)``print``(``"Value of n = {} and k = {}"``.``format``(n, k))``  ` `# Use sympy.tribonacci() method ``nth_tribonacci_poly ``=` `tribonacci(n, k)  ``     ` `print``(``"The nth tribonacci polynomial : {}"``.``format``(nth_tribonacci_poly))  `

Output:

```Value of n = 5 and k = x
The nth tribonacci polynomial : x**8 + 3*x**5 + 3*x**2
```

Example #3:

 `# import sympy ``from` `sympy ``import` `*` ` ` `n ``=` `6``k ``=` `3``print``(``"Value of n = {} and k = {}"``.``format``(n, k))``  ` `# Use sympy.tribonacci() method ``nth_tribonacci_poly ``=` `tribonacci(n, k)  ``     ` `print``(``"The nth tribonacci polynomial value : {}"``.``format``(nth_tribonacci_poly))  `

Output:

```Value of n = 6 and k = 3
The nth tribonacci polynomial value : 68289
```

My Personal Notes arrow_drop_up