(Solved) : Bisection Search Cant Seem Get Exact Answers Test Cases Help Please Simplify Things Assume Q30592157 . . .
Bisection Search: (i cant seem to get exact answers as testcases? any help please.)
To simplify things,assume:
Your semi-annual raise is .07 (7%)
Your investments have an annual return of 0.04 (4%)
The down payment is 0.25 (25%) of the cost of the house
The cost of the house that you are saving for is $1M.
You are now going totry to find the best rate of savings to achieve a down payment on amillion dollar house in 36 months. Since hittingthis exactly is a challenge, we simply want your savings to bewithin $100 of the required down payment.
For house_hunting3()write a program to calculate the best savings rate, as a functionof your starting salary. You should use bisectionsearch to help you do this efficiently. You should keeptrack of the number of steps it takes yourbisections search to finish. You should be able to reuse some ofthe code you wrote for house_hunting2() in this problem.
Because we aresearching for a value that is in principle a float, we are going tolimit ourselves to two decimals of accuracy (i.e., we may want tosave at 7.04% or 0.0704 in decimal – but we are not going to worryabout the difference between 7.041% and 7.039%). This means we cansearch for an integer between 0 and 10000 (using integer division),and then convert it to a decimal percentage (using float division)to use when we are calculating the current_savings after 36 months.By using this range, there are only a finite number of numbers thatwe are searching over, as opposed to the infinite number ofdecimals between 0 and 1. This range will help prevent infiniteloops. The reason we use 0 to 10000 is to account for twoadditional decimal places in the range 0% to 100%.
Your function shouldreturn a tuple with the two values – best savings rate, and stepsin bisection search: (0.0704, 12). Best savings rate should be adecimal (e.g. 0.0704 for 7.04%). Keep in mind it may not bepossible to save a down payment in a year and a half for somesalaries. In this case your function should return None.
Note: Thereare multiple right ways to implement bisection search/number ofsteps so your results may not perfectly match those of the testcase.
Hints
There may be multiple savings rates that yield a savings amountthat is within $100 of the required down payment on amillion dollar house. In this case, you can justreturn any of the possible values.
Depending on your stopping condition and how you compute a trialvalue for bisection search, your number of steps may vary slightlyfrom the example test cases.
Watch out for integer division when calculating if a percentagesaved is appropriate and when calculating final decimal percentagesavings rate.
Remember to reset the appropriate variable(s) to their initialvalues for each iteration of bisection search.
In [ ]:
def house_hunting3(annual_salary): “”” Provide function docstring “”” return
TestCases
Sample test cases are provided in the table below.
annual_salarysavingsratebisectionsteps1500000.4411123000000.2206910000None
Expert Answer
Answer to Bisection Search Cant Seem Get Exact Answers Test Cases Help Please Simplify Things Assume Q30592157 . . .
OR