Skip to content

Commit b1a5b74

Browse files
committed
Fibonacci
1 parent ef77f6c commit b1a5b74

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
A simple program that generate the Fibonacci sequence of N numbers.
3+
"""
4+
5+
if __name__ == '__main__':
6+
fibonacci_numbers = [0, 1]
7+
while True:
8+
try:
9+
N = int(input("Enter how many numbers the Fibonacci sequence will have: "))
10+
if N <= 1:
11+
test = N / 0
12+
break
13+
except ValueError:
14+
print("Wrong input. Try again.")
15+
except ZeroDivisionError:
16+
print("Value must be greater than 1.")
17+
18+
for i in range(N - 2):
19+
fibonacci_numbers.append(fibonacci_numbers[i] + fibonacci_numbers[i + 1])
20+
print(fibonacci_numbers)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
In mathematics, the Fibonacci numbers, commonly denoted Fn form a sequence, called the Fibonacci sequence, such that each number is the sum of the two preceding ones, starting from 0 and 1. That is,[1]
3+
4+
F 0 = 0 , F 1 = 1 ,
5+
6+
and
7+
8+
F n = F n − 1 + F n − 2 ,
9+
10+
for n > 1.
11+
12+
One has F2 = 1. In some books, and particularly in old ones, F0, the "0" is omitted, and the Fibonacci sequence starts with F1 = F2 = 1.[2][3] The beginning of the sequence is thus:
13+
14+
( 0 , ) 1 , 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 , 55 , 89 , 144 ,...

0 commit comments

Comments
 (0)