in Python by
Q:
Write a program to display the Fibonacci sequence in Python?

1 Answer

0 votes
by
1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

# Displaying Fibonacci sequence

n = 10

# first two terms

n0 = 0

n1 = 1

#Count

x = 0

# check if the number of terms is valid

if n <= 0:

   print("Enter positive integer")

elif n == 1:

   print("Numbers in Fibonacci sequence upto",n,":")

   print(n0)

else:

   print("Numbers in Fibonacci sequence upto",n,":")

   while x < n:

       print(n0,end=', ')

       nth = n0 + n1

       n0 = n1

       n1 = nth

       x += 1

Output:

1

0, 1, 1, 2, 3, 5, 8, 13, 21, 34,
Click here to read more about Python
Click here to read more about Insurance

Related questions

+1 vote
asked Feb 15 in Python by SakshiSharma
0 votes
asked May 17, 2020 in Python by sharadyadav1986
0 votes
asked Mar 13, 2020 in Agile by yourell
0 votes
asked Jan 10 in Python by rajeshsharma
0 votes
asked Sep 3, 2019 in JAVA by Robin
0 votes
asked Dec 22, 2019 in Python by rajeshsharma
...