forked from Zipcoder/PyPart4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfibonacci_linear.py
More file actions
38 lines (27 loc) · 856 Bytes
/
fibonacci_linear.py
File metadata and controls
38 lines (27 loc) · 856 Bytes
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
"""
Exercise 3
Create a program called fibonacci_linear.py
Requirements
Given a term (n), determine the value of x(n).
In the fibonacci_linear.py program, create a function called fibonnaci. The function should take in an integer and return the value of x(n).
This problem must be solved WITHOUT the use of recursion.
Constraints
n >= 0
Answer below:
"""
n = int(input("Provide a number greater than or equal to 0: "))
def fibonacci(n):
first_num=0
second_num=1
if n>=0:
for i in range(1,n,1):
third_num = first_num + second_num
first_num = second_num
second_num = third_num
print(third_num)
else:
print("You need to provide a valid input to run the function")
if n>=0 and n<=30:
fibonacci(n)
else:
print("You need to provide a valid input to run the function")