Lucas Series

Generate Lucas series (2, 1, 3, 4, 7, ...).

Logic BuildingIntermediate
Logic Building
# Take n
n = int(input("Enter number of terms: "))

# Generate Lucas series
if n <= 0:
    print("Invalid input")
elif n == 1:
    print("2")
elif n == 2:
    print("2 1")
else:
    a, b = 2, 1
    print(a, b, end=" ")
    for i in range(2, n):
        c = a + b
        print(c, end=" ")
        a, b = b, c
    print()

Output

Enter number of terms: 8
2 1 3 4 7 11 18 29

Lucas series: starts with 2, 1.

Key Concepts:

  • Start with 2, 1
  • Each next = sum of previous two
  • Similar to Fibonacci