Q3) Write a menu driven program in python to evaluate the following recursive functions. Also define a decorator to validate the arguments passed to the functions. (i) f(n) if n=0 nf(n-1) if n>0 (ii) f(n) = 1 (iii) f(n) = f(n-2) + f(n-1) (100 (3 + f(n-1) 3 (iv) f(n) = 6 Sample Input: n=4 if n = 0 if n = 1 if n > 1 if n = 0 if n > 0 f(n-1)+6f(n-2) if n = 0 if n = 1 if n ≥ 2 The decorator should validate the value of n such that, if n<0 raise an exception and display "Invalid argument!!!", return the function otherwise. Expected Output after evaluating each function: (i) 24 (ii) 5 (iii) 8100 (iv) 204 If the input is -3 in all the cases, the functions will not be executed but it will raise the given error message. (Invalid argument!!!)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Q3) Write a menu driven program in python to evaluate the following recursive functions. Also
define a decorator to validate the arguments passed to the functions.
(i) f(n):
-{nf(n-1)
if n = 0
nf(n-1) if n>0
(ii) f(n) = 1
(iii) f(n) =
f(n-2) + f(n-1)
(100
if n = 0
(3* f(n-1) if n > 0
(iv) f(n) = 6
(iii) 8100
(iv) 204
f(n-1) +6f(n − 2)
if n = 0
if n = 1
if n > 1
Sample Input:
n=4
The decorator should validate the value of n such that, if n<0 raise an exception and display "Invalid
argument!!!", return the function otherwise.
if n = 0
if n = 1
if n ≥ 2
Expected Output after evaluating each function:
(i) 24
(ii) 5
If the input is -3 in all the cases, the functions will not be executed but it will raise the given error
message. (Invalid argument!!!)
Transcribed Image Text:Q3) Write a menu driven program in python to evaluate the following recursive functions. Also define a decorator to validate the arguments passed to the functions. (i) f(n): -{nf(n-1) if n = 0 nf(n-1) if n>0 (ii) f(n) = 1 (iii) f(n) = f(n-2) + f(n-1) (100 if n = 0 (3* f(n-1) if n > 0 (iv) f(n) = 6 (iii) 8100 (iv) 204 f(n-1) +6f(n − 2) if n = 0 if n = 1 if n > 1 Sample Input: n=4 The decorator should validate the value of n such that, if n<0 raise an exception and display "Invalid argument!!!", return the function otherwise. if n = 0 if n = 1 if n ≥ 2 Expected Output after evaluating each function: (i) 24 (ii) 5 If the input is -3 in all the cases, the functions will not be executed but it will raise the given error message. (Invalid argument!!!)
Expert Solution
Step 1

Answer:

Algorithms

Step1: We have create a function as f1 and takes as input n and check if n is 0 then return 1 otherwise return n*f1(n-1)

Step2: We have create a function as f2 and takes as input n and check if n is 0 and n is 0  then return 1 otherwise return f2(n-1)+f2(n-2)

Step3: We have create a function as f3 and takes as input n and check if n is 0 then return 100 otherwise return 3*f3(n-1)

Step4: We have create a function as f4 and takes as input n and check if n is 0 then return 3 and n is 1 then return 6  otherwise return f4(n-1)+6*f4(n-2)

Step5: Next we check the number is negative of not if negative then print invalid arguments

Step6: lastly call the function and print it 

steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY