[go: up one dir, main page]

0% found this document useful (0 votes)
7 views4 pages

Paper Number 2

The document outlines an online examination for a Data Structures and Algorithms course, focusing on implementing a recursive Fibonacci function in Python. Students are required to write a program that reads an integer input, calculates the Fibonacci number using the recursive algorithm, and displays the output until -1 is entered. A grading sheet is provided, detailing criteria for evaluation including compilation, execution, input handling, and code quality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Paper Number 2

The document outlines an online examination for a Data Structures and Algorithms course, focusing on implementing a recursive Fibonacci function in Python. Students are required to write a program that reads an integer input, calculates the Fibonacci number using the recursive algorithm, and displays the output until -1 is entered. A grading sheet is provided, detailing criteria for evaluation including compilation, execution, input handling, and code quality.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

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()

You might also like