Pell Series
Generate Pell numbers with pair updates. Students multiply the previous term by two before adding the earlier term and handle short sequence counts explicitly.
1# Take n2n = int(input("Enter number of terms: "))34# Generate Pell series5if n <= 0:6 print("Invalid input")7elif n == 1:8 print("0")9elif n == 2:10 print("0 1")11else:12 a, b = 0, 113 print(a, b, end=" ")14 for i in range(2, n):15 c = 2 * b + a16 print(c, end=" ")17 a, b = b, c18 print()
Output
Enter number of terms: 8 0 1 2 5 12 29 70 169
In this one
- Apply the Pell recurrence
- Preserve old pair values
- Handle initial terms
How it works
- 1
Handle counts zero through two with dedicated branches.
- 2
Compute c = 2 * b + a.
- 3
Print c before updating a and b.
Edge cases
What is the next term after 0, 1, 2?
What is the next term after 0, 1, 2?
Five.
What if n = 2?
What if n = 2?
Only zero and one print.
What's going on
The starting terms are zero and one. Each new c is 2 * b + a, where b is the latest term and a the one before it.
Simultaneous assignment shifts the pair only after c is calculated. For five terms, the output is 0 1 2 5 12. This is not ordinary Fibonacci addition. Nonpositive counts are rejected before any sequence values print.
What is the next term after 0, 1, 2? Five.
What if n = 2? Only zero and one print.
Quiz
Tap an option. The answer stays hidden until you pick.
Question 1
Which recurrence is used?
Pick an answer to check it.
Question 2
What is the next term after 0, 1, 2?
Pick an answer to check it.
Questions people ask
What is the next term after 0, 1, 2?
Five.
What if n = 2?
Only zero and one print.
Which recurrence is used?
2 * b + a.
๐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