# #38 Python Tutorial for Beginners | Fibonacci Sequence

///#38 Python Tutorial for Beginners | Fibonacci Sequence
• ## #38 Python Tutorial for Beginners | Fibonacci Sequence  Add to favorites

Github :-

source

By |2019-10-07T23:14:32+00:00October 7th, 2019|Python Video Tutorials|21 Comments

1. Arjya Basu October 7, 2019 at 11:14 pm - Reply

n=int(input("Enter the limit of the fibonacci series"))
a=0
b=1
print(a,end=" ")
print(b,end=" ")
for i in range(0,n-2):
c=a+b
a=b
b=c
print(c,end=" ")

2. Kishore Borkakoti October 7, 2019 at 11:14 pm - Reply

Here's my program, including some of the assignments of the video.

x = int(input('How many Fibonacci nos. you want: '))

a = 0

b = 1

if x == 0:

print ('None')

elif x == 1:

print(a , end=" ")

elif x == 2:

print(a , b , end= " ")

elif x > 2:

print(a , b , end= " ")

while x > 2:

c = a

a = b

b = b + c

print (b , end= " ")

x -= 1

else:

print('Sorry !! The program can only process the positive nos at present.')

3. MCN Videos October 7, 2019 at 11:14 pm - Reply

Hi Naveen, thanks for your all tutorials, really appreciated,
I am facing one issue in Fibonacci program which is same as your program.

I want to print Fibonacci series till n but it returns more that n

4. Achintya Asthana October 7, 2019 at 11:14 pm - Reply

n=int(input("Input the length of series : "))

def fib(n):

a=0

b=1

if n==1:

print(a)

else:

print(a)

print(b)

for i in range(2,n):

c=a+b

a=b

b=c

if c<=100:

print(c)

fib(n)

5. RBK. technology October 7, 2019 at 11:14 pm - Reply

We can use if elif and else inside the function. So we can avoid neg num. We can prompt user by a msg. Plsease enter a valid num.

6. Suhashini Nathan October 7, 2019 at 11:14 pm - Reply

Hey how to check if a number is part of Fibonacci sequence?

7. Sangram Panda October 7, 2019 at 11:14 pm - Reply

Sir,my solution for first assignment is
//*we write a if condition after the function declaration*//
if n>=1
//write the same code as written by u//
else:
print("invalid")
the second assignment solution is given bellow

if c<=n:
print(c) //*give me replay sir*//

8. OVERWATCH Gaming only October 7, 2019 at 11:14 pm - Reply

Aliens??? WTF

9. shivam bharti October 7, 2019 at 11:14 pm - Reply

10. shivam bharti October 7, 2019 at 11:14 pm - Reply

Sir write the program with while loop

11. LITE GAMERS October 7, 2019 at 11:14 pm - Reply

12. Vijit Kumawat October 7, 2019 at 11:14 pm - Reply

Pattern here is (after 0,1 adding 2 digits and write the ans…….again add the two and right the ans……🙂🙂)

13. rohit kumar October 7, 2019 at 11:14 pm - Reply

def fabo(x):

a=0

b=1

if x<0:

print('invalid number')

elif x==1:

print(a)

else:

for i in range (x):

c= a+b

a=b

b=c

print(c)

x= int(input('enter a number:'))

fabo(x)

Sir please give some idea how to start project??

14. Joshua Garang October 7, 2019 at 11:14 pm - Reply

Hello Telusko, kindly make a series on programming challenges/questions only. This can help us much!

15. INCREDIABLE CREATIONS October 7, 2019 at 11:14 pm - Reply

U are awesome👏✊👍

16. Farhat October 7, 2019 at 11:14 pm - Reply

is this right?
I created a list first with elements from 0 to 10:
for i in range(11):
mylist.append(i)

then
for i in range(2,len(mylist),1):
mylist[i]=mylist[i-1]+mylist[i-2]

17. Vishal Bharat October 7, 2019 at 11:14 pm - Reply

I have a doubt…. Why is b=c in the program?

18. mohmmed zikrullah October 7, 2019 at 11:14 pm - Reply

sir while printing the outpur in the same line
its not happening

19. Gangaram Siddam October 7, 2019 at 11:14 pm - Reply

assignment solution without functions:
a=0

b=1

range=int(input("enter the Range"))

if range<0:

print("invalid range")

elif range==1:

print(a)

else:

print(a)

print(b)

c = a + b

while c<=range:

print(c)

a=b

b=c

c=a+b

20. Kinglsey Ihemere October 7, 2019 at 11:14 pm - Reply

I am actually feeling good right now

def fib(n):
a = 0
b = 1
if n < 0:

elif n == 1:
print(a)
else:
print(a)
print(b)

for i in range(2, n):
c = a + b
a = b
b = c
print(c)

fib(5)

21. Arjun Singh October 7, 2019 at 11:14 pm - Reply

fibonacci <= n

def fib(n):

a=0

b=1

if n<1:

print("Enter Correct Value")

elif n==1:

print(a)

else:

print(a)

print(b)

for i in range(2,n):

c=a+b

a=b

b=c

if c>n:

break

print(c)

fib(100)