Project: Fibonacci number

The first and second numbers in the Fibonacci sequence are both 1. After that, each number is the sum of the two before it: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, and so on.

Write a function called fibonacci that takes a positive integer and returns the number at that position in the sequence. For example, fibonacci(1) is 1, fibonacci(3) is 2 and fibonacci(5) is 5. The function does not print anything. It returns a value:

term = fibonacci(17)

Do not use recursion. Your function must not call itself.

Save the file as fibonacci.py.

Show a solution

Try the project on your own first. This is one working solution, followed by its tests. Press Run to run the tests. Read them to see what thorough testing looks like, then change the solution and run again to watch a test fail. The testing tools used here (classes and unittest) are not part of the course yet, so do not worry about how they work.

Projects run on your own computer, so you tell us when you are done.