forked from dchandnani/Notebooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci.py
More file actions
56 lines (46 loc) · 1.46 KB
/
fibonacci.py
File metadata and controls
56 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import math
import numpy as np
import plotly.express as px
from plotly.subplots import make_subplots
# Program to display the Fibonacci sequence up to n-th term
def fibonacci():
nterms = 20
# first two terms
n1, n2 = 0, 1
count = 0
data = [0, 1]
# check if the number of terms is valid
if nterms <= 0:
print("Please enter a positive integer")
# if there is only one term, return n1
elif nterms == 1:
print("Fibonacci sequence upto", nterms, ":")
print(n1)
# generate fibonacci sequence
else:
print("Fibonacci sequence:")
while count < nterms:
nth = n1 + n2
data.append(nth)
n1 = n2
n2 = nth
count += 1
return data
def plotSeries(data):
fig = make_subplots(rows=1, cols=2)
fig = px.bar(data, color_discrete_sequence=['purple']*len(data))
fig.update_layout(title_text="<b>Fibonacci Series</b>",
title_font=dict(family="Arial", size=20, color='silver'))
fig.update_layout(
{'plot_bgcolor': 'rgba(0, 0, 0, 0)',
'paper_bgcolor': 'rgba(0, 0, 0, 0)', })
fig.update_yaxes(
color='rgba(100,100,100,1)',
showgrid=True, gridcolor='rgba(100,100,100,1)',
zerolinewidth=1, zerolinecolor='rgba(100,100,100,1)')
fig.update_xaxes(color='rgba(100,100,100,1)')
fig.update_layout(showlegend=False)
fig.show()
data = fibonacci()
print(data)
#plotSeries(data)