Fibonacci series - Answers
Q1. Get the code working.
Q2. The code produces a Fibonacci series up to but not exceeding n. A Fibonacci series starts with a 0 and a 1. To get the next number in a sequence, you add up the previous two numbers. So the next number here is 0 and 1, which is 1. You now have 0, 1, 1 in the sequence. To get the nex number, add 1 + 1 to get 2, so you now have 0, 1, 1, 2 in the sequence. The Fibonacci series is very importance in Maths and surprising appears in all kinds of places.
Q3. Line 2 is the doc string for the function. It is important to document all functions because they may have to be read and changed by someone else in the future. Also, they are used to generate program documentation automatically.
Q4. Initialisation is when you give variables starting values. This occurs on lines 3 and 4 in this program.
Q5. a is given the value of b, whilst b is given the value of a + b at the same time i.e. although a just received a new value, this new value isn't used here for a + b (because it is on the same line).
Q6. Replacing the code results in a new series being produced, which isn't the Fibonacci series. This is because first, a is given the value of b. Then, b is given the value of a + b using the new value of a. If you are unsure of how this works or are having trouble visualising what is happing as the code is run, you should create a table and dry-run the code. you can use the following table:
Q7. The Fibonacci series appears in nature in many places. A Google search og 'Fibonacci series in nature' will produce many examples.