The Lucas Numbers are a sequence very similar to the Fibonacci sequence discusse
ID: 3726595 • Letter: T
Question
The Lucas Numbers are a sequence very similar to the Fibonacci sequence discussed in class, the only difference being that the Lucas Numbers start with 10-2 L,-1 as opposed to Fibonacci's Fo = 0 and F1 = 1, concretely, they are defined by Lo = 2, L,-1 and Ln-Ln-l + Ln-2 for n > 1 Write a Python function called first D_digit Lucas that takes an integer argument D less than 30 and returns the first D-digit Lucas number. For example Result Test print(first_D_ digit_Lucas(2)) 11 print(first_ D_digit_Lucas (3)) 123 Answer: (penalty regime: 0 %)Explanation / Answer
def first_D_digit_Lucas(n) :
if (n<30):
#base cases
if (n == 0) :
return 2
if (n == 1) :
return 1
# recurrence relation
return first_D_digit_Lucas(n - 1) + first_D_digit_Lucas(n - 2)
D = int(input("Enter number "))
#to print upto D lucas numbers
for i in range(0,D):
print(first_D_digit_Lucas(i))
#to print D th lucas number
print(first_D_digit_Lucas(i))
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.