Page 1 of 1

Python

Posted: Sat May 14, 2022 3:17 pm
by answerhappygod
Python
Python 1
Python 1 (112.78 KiB) Viewed 53 times
Consider some mathematical function f defined such that f()= if(n)=f(n-1)+2) {sin 1937–132} Write a python function evaluate_f(number) which takes an integer as a parameter and computes the tuple (f(n), k) where k is the number of recursive function calls required to compute f(n). Note that the number of recursive function calls does not include the initial function call, e.g. for f(0) the number of recursive function calls is zero (base case, so result is returned without recursive call) and for f(1) the number of recursive function calls is one (recursive call of f(-1)). You can assume that all input to the function will be an integer >= 1. This function has to be recursive; you are not allowed to use loops to solve this problem! For example: Test Result val = evaluate_f(3) (7, 2) print(val) (5, 1) val = evaluate_f(2) print(val) val = evaluate_f(4) (9, 3) print(val) val = evaluate_f(8) (17, 7) print(val) Amor 101 20 или Есло