Lucas Series
Generate Lucas numbers with a two-value update. Students compare Lucas starting values with Fibonacci and trace the same addition rule on different seeds.
1# Take n2n = int(input("Enter number of terms: "))34# Generate Lucas series5if n <= 0:6 print("Invalid input")7elif n == 1:8 print("2")9elif n == 2:10 print("2 1")11else:12 a, b = 2, 113 print(a, b, end=" ")14 for i in range(2, n):15 c = a + b16 print(c, end=" ")17 a, b = b, c18 print()
Output
Enter number of terms: 8 2 1 3 4 7 11 18 29
In this one
- Choose a different seed pair
- Keep a two-term recurrence
- Validate the term count
How it works
- 1
Handle nonpositive counts and short outputs.
- 2
Start the longer case from two and one.
- 3
Print each sum and advance a, b together.
Edge cases
What does n = 1 print?
What does n = 1 print?
Two.
Is the addition rule different from Fibonacci?
Is the addition rule different from Fibonacci?
No. The starting pair differs.
What's going on
The Lucas sequence here starts two, one. Subsequent terms add the previous two, just as Fibonacci does with different initial values.
Short branches print one or two terms directly. Otherwise the loop prints new sums and shifts the pair together. Five terms are 2 1 3 4 7. The entered n is a term count, and nonpositive values get an invalid-input message.
What does n = 1 print? Two.
Is the addition rule different from Fibonacci? No. The starting pair differs.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
What follows 2, 1, 3?
Pick an answer to check it.
Question 2
What does n = 1 print?
Pick an answer to check it.
Questions people ask
What does n = 1 print?
Two.
Is the addition rule different from Fibonacci?
No. The starting pair differs.
What follows 2, 1, 3?
4.
๐Related Content
- ๐
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- ๐
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- ๐ป
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- ๐
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- ๐ง
Logic Building Overview
Learn about the complete logic building curriculum