-
Notifications
You must be signed in to change notification settings - Fork 3
/
fib.py
71 lines (56 loc) · 1.54 KB
/
fib.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
fir = 0
sec = 1
fg = input("Enter 'f' for Fibonacci's sequence or 'g' for Golden Ratio sequence: ").lower()
# Text will be shown in red in the terminal
ip = input("Enter how far you want to see the sequence go, or don't specify any value to make it go on forever: ")
if fg == "f":
# Printing the start of the seq
print(fir)
print(sec)
# If no input given then go on forever
if ip == "":
while True:
j = fir + sec
print(j)
# Give fir, sec's value because sec is now fir
fir = sec
# Make sec = fir + sec
sec = j
# Else go only till specified input
else:
for i in range(int(ip) - 2):
f = fir + sec
print(f)
# Give fir, sec's value because sec is now fir
fir = sec
# Make sec = fir + sec
sec = f
# Golden Ration - bigger/smaller numbers in the sequence.
# As sequence progresses, this number tends towards 1.618 --> The Golden Ratio
else:
if ip == "":
while True:
f = fir + sec
# To show the GOLDEN RATIO
try:
g = sec / fir # Golden Ratio
print(g)
except ZeroDivisionError:
print("-")
# Give fir, sec's value because sec is now fir
fir = sec
# Make sec = fir + sec
sec = f
else:
for i in range(int(ip) - 2):
f = fir + sec
# To show the GOLDEN RATIO
try:
g = sec / fir # Golden Ratio
print(g)
except ZeroDivisionError:
print("-")
# Give fir, sec's value because sec is now fir
fir = sec
# Make sec = fir + sec
sec = f