Open In App

Python | sympy.lucas() method

Last Updated : 26 Jul, 2019
Improve
Improve
Like Article
Like
Save
Share
Report
With the help of sympy.lucas() method, we can find Lucas numbers in SymPy.

lucas(n) -

Lucas numbers satisfy a recurrence relation similar to that of the Fibonacci sequence, in which each term is the sum of the preceding two. They are generated by choosing the initial values L_0 = 2 and L_1 = 1 and the recurrence relation L_n = L_{n-1} + L_{n-2}.
Syntax: lucas(n) Parameter: n – It denotes the number upto which lucus number is to be calculated. Returns: Returns the nth lucas number.
Example #1:
# import sympy 
from sympy import * 
  
n = 7
print("Value of n = {}".format(n))
   
# Use sympy.lucas() method 
nth_lucas = lucas(n)  
      
print("Value of nth lucas number : {}".format(nth_lucas))  

                    
Output:
Value of n = 7
Value of nth lucas number : 29
Example #2:
# import sympy 
from sympy import * 
  
n = 10
print("Value of n = {}".format(n))
   
# Use sympy.lucas() method 
n_lucas = [lucas(x) for x in range(11)]  
      
print("N lucas number are : {}".format(n_lucas))  

                    
Output:
Value of n = 10
N lucas number are : [2, 1, 3, 4, 7, 11, 18, 29, 47, 76, 123]


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads