migrate to git.charlotte.sh
This commit is contained in:
commit
fbd588721e
412 changed files with 13750 additions and 0 deletions
15
python-csi160/week06/week6practiceproblems/part6.py
Normal file
15
python-csi160/week06/week6practiceproblems/part6.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
def fibonacci(n):
|
||||
"""Return the nth Fibonacci number.
|
||||
|
||||
param n: (int) position to determine fibonacci of
|
||||
return: (int) value at position n
|
||||
"""
|
||||
|
||||
fib_numbers = [0, 1]
|
||||
for i in range(2, n + 1):
|
||||
fib_numbers.append(fib_numbers[i - 1] + fib_numbers[i - 2])
|
||||
return fib_numbers[n]
|
||||
|
||||
# Leave this part for easily testing your function
|
||||
print('fibonacci(6) returns:', fibonacci(6), 'expected 8')
|
||||
print('fibonacci(3) returns:', fibonacci(3), 'expected 2')
|
Loading…
Add table
Add a link
Reference in a new issue