Laboratory Walkthrough 4 - Submissiondeadline...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Intro2cs Ex4 – Pensioners Submission deadline Thursday,14 Novembe r, 20:55 Objectives In this exercise you will practice the use of basic algorithms as binary search and bubble sort. You will also have a deeper understanding of functions and containers. Ex3 Ex3 is also online. you must complete Ex3 before start working on this exercise. Some of the skills needed for Ex4 will be discussed in the “tirgulim” of next week. But, after completing ex3, you may choose to start working on this exercise before them. Being a Pensioner Ex3 dealt with the issue of “planning for the future”. On Ex4, you should find your time machine in the garage since you are becoming a pensioner. You may use your own code from Ex3 (and only yours) in this exercise, but it must be copy pasted into your code (i.e. you are not allowed to import it) We will suppose you want to "live like a king" until your death. You don't have any children and you want to make the most out of your retirement – i.e. you want to maximize your expenses without entering into debts. We will assume constant expenses on each year. How may we calculate it? One option would be to try feeding different values of expenses to post_retirement() – and find the best value (i.e. maximum expenses such that the last value in the returned list will still be a positive) Remember that in class we saw the idea of binary search. We can use this idea also here to find the correct value. In this assignment you may choose to use also pure arithmetics for this calculation. Assignment 1 Implement live_like_a_king , which takes five arguments: a salary , a percentage of your salary to save ( save ), a list of annual growth rate before retirement ( pre_retire_growth_rates ), a list for after the retirement ( post_retire_growth_rates ), and a value for stop searching ( epsilon ). As before the length of the will be the amount of working years and will account for the number of years you live after retirement. Find the maximal expenses you can withdraw each year from your retirement fund, such that by your
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
death, you will have a positive amount in your bank. You may use binary search in order to find the maximal expenses. In order not to continue forever you should stop when your expenses result in a positive value which is smaller than epsilon. Special 5 points bonus will be given to those of you who instead of using binary search will use arithmetics and will return a value that will leave your account with 0 in the end of your life. Specify in your README which method did you use. Your function should return the maximal expenses value you found. Complete: live_like_a_king(salary, save, pre_retire_growth_rates, post_retire_growth_rates, epsilon) Write your code in the appropriate place in the ex4.py template. To test your function, compare it with the school solution.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 6

Laboratory Walkthrough 4 - Submissiondeadline...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online