Data Structures and Algorithms IT2070
Year two Semester two 2020
Online Examination
Sri Lanka Institute of Information Technology
Time: 30 minutes
________________________________________________________________________
Paper Number 2 (20 marks)
The Fibonacci sequence is the series of numbers:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34,
The next number is found by adding up the two numbers before it as given by the
following mathematical function.
A recursive algorithm for the Fibonacci calculation is given below:
a) Write a program in Python to read an integer from the keyboard.
b) Develop a function in python named as Fibonacci and implement the above
recursive algorithm.
c) Pass the input number as parameter to the function developed and get the
Fibonacci number as output.
d) Use the loop to run the program and display the correct output until user inputs -1.
Upload your answer using given template to the course web link “Paper Number 2”
Grading Sheet:
1) Program is compiling. 2 marks
2) Program is running successfully. 2 marks
3) Program takes the input number as integer. 2 marks
4) Correct implementation Fibonacci function. 6 marks
5) Correct output 2 marks
6) Use of loop correctly 4 marks
7) Include comments and properly indented. 2 marks
8) Plagiarism testing tool results:…………………………..
def FIBONACCI(n):
if n <= 1:
return n
else:
return FIBONACCI(n - 1) + FIBONACCI(n - 2)
def main():
while True:
try:
number= int(input("Enter the numbers :"))
print({number})
if number==-1:
break
else :
print(f"The Fibonacci number at position {number} is: {FIBONACCI(number)}")
except ValueError:
print("Non integer number Entered")
main()