Answer to Question #265022 in Python for raj

Question #265022

To find the lucky number.

Input - 8, Output - 21

Write an algorithm to make a list like 1,1,2,3,5,8,13,21 so when input 8 is entered it

should give output 21


1
Expert's answer
2021-11-12T17:33:43-0500


SOLUTION TO THE ABOVE QUESTION


SOLUTION CODE


#propmt the user to enter a number
print("\nINPUT:")
my_number = int(input("Enter a random number to find your lucky number: "))
#declare an empty list
my_lucky_numbers_list = []
first = 1;
my_lucky_numbers_list.append(first)
second = 1;
my_lucky_numbers_list.append(second)
for i in range(2, (my_number + 2)):
    next = first + second;
    my_lucky_numbers_list.append(next)
    first = second
    second = next

print("\nOUTPUT:")
print("Your lucky number is "+str(my_lucky_numbers_list[my_number-1]))


SAMPLE OUTPUT PROGRAM







Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS