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
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
Comments
Leave a comment