Python | sympy.lucas() method

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))  

chevron_right


Output:

Value of n = 7
Value of nth lucas number : 29

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))  

chevron_right


Output:

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


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.