I need help with Problem 4 from PS4. I cannot figure out what my if statement should be in the binary search. If I do the problem manually, knowing the answer it's easy as I know when to assign the guess from low to high. I get the correct answers for parts 1-3, so I know that's not the issue.

At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get our expert's

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions.

A community for students.

I need help with Problem 4 from PS4. I cannot figure out what my if statement should be in the binary search. If I do the problem manually, knowing the answer it's easy as I know when to assign the guess from low to high. I get the correct answers for parts 1-3, so I know that's not the issue.

MIT 6.00 Intro Computer Science (OCW)
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Get this expert

answer on brainly

SEE EXPERT ANSWER

Get your free account and access expert answers to this and thousands of other questions

def findMaxExpenses(salary, save, preRetireGrowthRates, postRetireGrowthRates, epsilon): low = 0 est_high = nestEggVariable(salary, save, preRetireGrowthRates) high = est_high[-1] # amount of money at start of retirement guess = (low + high)/2.0 retirement_list = postRetirement(high, postRetireGrowthRates, guess) money_end_retirement = retirement_list[-1] print money_end_retirement while abs(money_end_retirement) > epsilon: print guess # printing the expenses guess each iteration if ?????: high = guess guess = (low + high) / 2.0 retirement_list = postRetirement(high, postRetireGrowthRates, guess) money_end_retirement = retirement_list[-1] else: low = guess guess = (low + high) /2.0 retirement_list = postRetirement(high, postRetireGrowthRates, guess) money_end_retirement = retirement_list[-1] print "final estimate is ", guess Am I on the right track? Any help is greatly appreciated! :)
Yes, you're on the right track. Figure out how your guess affects the money_end_retirement, and you will know what to check for in your IF statement.
Thanks Aslander!! Turns out my original assumption of if money_end_retirement < 0: was correct, but I had the wrong value for my savings in postRetirement function. It should've been the money at the start of retirement. It threw me off!

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

Not the answer you are looking for?

Search for more explanations.

Ask your own question