Computer Science, asked by heysaif, 18 days ago

Write a python function that takes an integer number (size) then it generates Fibonacci sequence with the given size. (Hint: The Fibonacci sequence is a sequence of numbers where the next number in the sequence is the sum of the previous nuo numbers in the sequence. The sequence looks like this: 7.1.2.3.5.8. 13...) For example: if we input 3 → the output will be 1, 1, 2 If we input 6 → the output will be 1. 7. 2.3.5.8​

Answers

Answered by anindyaadhikari13
6

Solution:

The given problem is solved using language - Python.

a=0

b=1

c=1

n=int(input('Enter the limit: '))

list=[]

for i in range(n):

   list.append(c)

   c=a+b

   a,b=b,c

print(*list,sep=', ')

Logic:

  • Accept the limit from the user.
  • Generate each term of the fibonacci series by adding previous two terms.
  • Initialise the previous two terms with their next terms.
  • Store the numbers in a list.
  • Display the numbers in the list separated by commas.

See attachment for output.

Attachments:
Similar questions