(Laboratory No. 3.2: Fibonacci) : Objectives
(Laboratory No. 3.2: Fibonacci) : Objectives
Materials:
1. PC or Laptop
2. Python Package Development Kit
3. Pycharm or any IDE
Background
In programming, a function that calls by itself multiple number of times is called Recursion. It is usually defined
as value returning function.
A recursive function is any function that fulfils the condition of recursion and has to be terminated when used
in a program. It can lead to an infinite loop if a condition is not met.
Example:
5! = 5 * 4!
4! = 4 * 3!
3! = 3 * 2!
2! = 2 * 1
Or it may be simply written as,
5! = 5 * 4 * 3 * 2 * 1 = 120
Below is a program that find factorial of number using for and while loops
Recursion at work!
Instructions:
and
for n > 1
Example:
The next number is found by adding up the two numbers before it.
(https://en.wikipedia.org/wiki/Fibonacci_number)
Create a program that accepts N (positive) integer and prints the Fibonacci sequence using
recursive function.
3. Input
4. Constraints
1≤N≤∞
5. Output
Your program should print the number series with its total.
6. Source Codes
sum = 0
def recursive(inputNumber):
if inputNumber <= 1:
return inputNumber
else:
return(recursive(inputNumber-1) + recursive(inputNumber-2))
7. Sample Input/Output
NOTE: Provide a screenshot and describe your observation for each action you performed based on
the item below:
When you enter zero value of a number it will display a message that you must enter a positive integer
because in the source code of the program there is a condition that it only accept positive integer.
When you enter negative value of a number it will display a message that you must enter a positive integer
because in the source code of the program there is a condition that it only accept positive integer.
When you enter any positive integer it will accept the number and compute the Fibonacci sequence and
will display the sequence as will as the sum of the numbers.
Rules:
1. Each laboratory activity has time limit of 1:30 minutes and is due on
the day depending on the level of difficulty or constraints.
2. Each activity will only last every after 3 days and has deduction of 10
points every day from the day it was given.