# Python | sympy.tribonacci() method

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

` `

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

Coder Machine Learner Social Activist Vocalist

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.