Computer Science, asked by cuteyboy23, 11 months ago

Wap to create a tuple of fibinacci series upto given limit. Please nice only

Answers

Answered by manavjaison
1

Heya friend,

Here we go :

First let us see what actually the Fibonacci series is :-

A Fibonacci series is the one where the third term of the series is equal to the preceding two terms and so on...

For eg :-

0 , 1 , 1, 2, 3, 5, 8 .....

[Here, we could see :- 0+1= 1 , 1+1=2,  2+1=3,  3+2=5, and so on...]

Now this program is for the fibonacci series upto a given limit, i.e., if the limit is :- 7 , the series should be like - (0, 1, 1, 2, 3, 5)

Special case if the limit is 0, the output should be :-

(0,)

As we want a tuple, so this the syntax of the singleton tuple, i.e. the tuple comprising of only a single element.

Now,

Let's see the code:

                           SOURCE CODE

#create fibonacci series upto a given limit

n=int(input('Enter the limit till you want the series:'))

a=0

b=1

if n==0:

   t=(0,)

   print('\n')

   print('The fibonacci series upto',n,'limit is:',t)

else:

   t=(0,1)

   c=a+b

   while c<=n:

       t=t+(c,)

       a,b=b,c

       c=a+b

   print('\n')

   print('The fibonacci series upto',n,'limit is:',t)

                                OUTPUT

Enter the limit till you want the series: 0

The fibonacci series upto 0 limit is: (0,)

>>>  

>>>  

Enter the limit till you want the series: 1

The fibonacci series upto 1 limit is: (0, 1, 1)

>>>  

>>>  

Enter the limit till you want the series: 12

The fibonacci series upto 12 limit is: (0, 1, 1, 2, 3, 5, 8)

>>>

Thanks !

#BAL #answerwithquality

Similar questions