Python | sympy.lucas() method
sympy.lucas()
Lucas numbers
lucas(n) -
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]