Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 00dd790

Browse files
Merge pull request #4 from Ali-Jahromi/issue1
Fibonacci sequence calculator added to the beginner level programs.
2 parents 944e85f + afe1339 commit 00dd790

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#Fibonacci sequence starts with 0 and 1 as the first numbers and the consequetive numbers are calculated by adding up the two numbers before them
2+
#0, 1, 1, 2, 3, 5, 8, 13 ...
3+
4+
# Function to claculate list of fibonacci numbers
5+
def fibonacci_calc(num):
6+
result = list()
7+
count = 0
8+
# Invalid input
9+
if num <= 0:
10+
print("Please enter a positive integer (input>0)")
11+
return result
12+
# Input 1
13+
elif num == 1:
14+
result.append(0)
15+
return result
16+
else:
17+
#starting values
18+
n1, n2 = 0, 1
19+
while count < num:
20+
result.append(n1)
21+
nth = n1 + n2
22+
n1 = n2
23+
n2 = nth
24+
count += 1
25+
return result
26+
27+
28+
if __name__ == "__main__":
29+
fibo_list = list()
30+
n = int(input("Please enter the sequence number: "))
31+
fibo_list = fibonacci_calc(n)
32+
for i in fibo_list:
33+
print(i)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /