-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci💯.py
More file actions
38 lines (35 loc) · 1.22 KB
/
Copy pathfibonacci💯.py
File metadata and controls
38 lines (35 loc) · 1.22 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
# a fibonacci algorithm, with some conditions
def gen_fibonacci(upper_bound):
try:
if isinstance(upper_bound, int) == False and isinstance(upper_bound, float) == False:
raise TypeError
elif isinstance(upper_bound, int) or isinstance(upper_bound, float):
if upper_bound < 0:
raise ValueError
except TypeError:
print("TypeError occured")
except ValueError:
print("ValueError occured")
counter = 0
alist = [0, 1]
if isinstance(upper_bound, int) or isinstance(upper_bound, float):
if upper_bound >= 1:
while counter < upper_bound:
alist.append(alist[-1] + alist[-1-1])
counter += 1
maximum = max(alist)
while True:
if maximum > upper_bound:
alist.remove(maximum)
maximum = max(alist)
else:
break
return alist
else:
while counter <= upper_bound:
alist = []
alist.append(0)
return alist
break
result = (gen_fibonacci(9.2)) # example
print(result)