Problem Set 1: Compound Interest: 1) Introduction
Problem Set 1: Compound Interest: 1) Introduction
Pset Buddy
You do not have a buddy assigned for this pset.
PLEASE DON'T DELETE ANY OF THE COMMENTS IN THE TEMPLATE PROVIDED AND USE THE VARIABLE
NAMES SPECIFIED BELOW TO GET FULL CREDIT!
1) Introduction
1.1) Objectives
Introduction to control flow in Python
Formulating a computational solution to a problem
Exploring bisection search
1.2) Overview
Complete each of the three problems in the respective python files: ps1a.py, ps1b.py and ps1c.py
Include comments to help us understand your code — read the Style Guide for more specific instructions regarding this.
ps1_tester.py is a tester file that you may run to test your code. Make sure ps1_tester.py is in the same folder as ps1a.py, ps1b.py, ps1c.py,
and put_in_function.py.
1.3) Collaboration
Students may work together, but each student should write up and hand in their assignment separately. Students may not submit the exact same
code.
Buddies may work together and submit the same code.
Students are not permitted to look at or copy each other's code or code structure.
Include the names of your collaborators in comment at the start of each file.
Please refer to the collaboration policy in the Course Information for more details.
1.4) Important Notes
Read the Style Guide sections 1, 2, 3, and 4.
If you get an error like ModuleNotFoundError: No module named 'ps1b_in_function' at any point, restart the Spyder kernel.
Get user input and declare variables under the correct comment headers in ps1a.py, ps1b.py, and ps1c.py. Failure to do so (e.g. using
different variable names where specified or declaring them under the wrong comment headers) will result in a 0 by the grader.
Do not remove or change any of the comments that are provided in the original ps1a.py, ps1b.py, and ps1c.py files.
The comments at the top of the files in the pset download may refer to 6.100A. This is because we use the exact same files for both 6.100A and
6.100L.
Test Case 2
Enter your yearly salary: 65000
Enter the percent of your salary to save, as a decimal: .20
Enter the cost of your dream home: 400000
Number of months: 79
Test Case 3
Enter your yearly salary: 350000
Enter the percent of your salary to save, as a decimal: .3
Enter the cost of your dream home: 10000000
Number of months: 189
Output.
1. Like Part A, your program should store the number of months required to save up for your down payment using a variable called months .
Notes
Like Part A, the investment amount used to calculate the monthly return is the amount you had saved at the start of each month.
Be careful about values that represent annual amounts versus monthly amounts.
Raises should only happen at the end of the 6th, 12th, 18th month, and so on.
If the number of months your program returns is off by one, reread the highlighted text above.
Assume that users enter valid inputs (e.g. no string inputs when expecting a float).
Your program should print outputs in the same format as the test cases below. If you're using Spyder, you might see extra lines in between
outputs. Don't worry about them!
3.1) Testing
3.1.1) Manual Test Cases
Test Case 1
Enter your starting yearly salary: 110000
Enter the percent of your salary to save, as a decimal: .15
Enter the cost of your dream home: 750000
Enter the semi-annual raise, as a decimal: .03
Number of months: 92
Test Case 2
Enter your starting yearly salary: 350000
Enter the percent of your salary to save, as a decimal: .3
Enter the cost of your dream home: 10000000
Enter the semi-annual raise, as a decimal: .05
Number of months: 131
r months
amount_saved = initial_deposit × (1 + )
12
You will use bisection search to determine the lowest rate of return r that is needed to achieve a down payment on a $800,000 house in 36 months.
Since hitting this exact amount is a bit of a challenge, we only require that your savings be within $100 of the required down payment. For example, if
the down payment is $1000, the total amount saved should be between $900 and $1100 (exclusive).
Your bisection search should update the value of r until it represents the lowest rate of return that allows you to save enough for the down payment in 3
years. r should be a float (e.g. 0.0704 for 7.04%). Assume that r lies somewhere between 0% and 100% (inclusive).
Outputs.
1. The variable steps should reflect the number of steps your bisection search took to get the best r value (i.e. steps should equal the number of
times that you bisect the testing interval).
2. The variable r should be the lowest rate of return that allows you to save enough for the down payment in 3 years.
Notes
There may be multiple rates of return that yield a savings amount that is within $100 of the required down payment on a $800,000 house. The
grader will accept any of these values of r .
If the initial deposit amount is greater than or equal to the required down payment minus $100, then the best savings rate is 0.0.
If it is not possible to save within $100 of the required down payment in 3 years given the initial deposit and a rate of return between 0%
and 100%, r should be assigned the value None .
Note: the value None is different than "None" . The former is Python's version of a null value, and the latter is a string.
Depending on your stopping condition and how you compute the amount saved for your bisection search, your number of steps may vary slightly
from the example test cases. Running ps1_tester.py should give you a good indication of whether or not your number of steps is close enough to
the expected solution.
If a test is taking a long time, you might have an infinite loop! Check your stopping condition.
Your program should print in the same format as the test cases below. If you're using Spyder, you might see extra lines in between outputs. Don't
worry about them!
4.1) Testing
4.1.1) Manual Test Cases
Test Case 1
Enter the initial deposit: 65000
Best savings rate: 0.380615234375 [or very close to this number]
Steps in bisection search: 12 [or very close to this number]
Test Case 2
Enter the initial deposit: 150000
Best savings rate: 0.09619140625 [or very close to this number]
4
Steps in bisection search: 11 [May vary based on how you implemented your bisection search]
Test Case 3
Enter the initial deposit: 1000
Best savings rate: None
Steps in bisection search: 0 [May vary based on how you implemented your bisection search]
5) Hand-in Procedure
5.1) Time and Collaboration Info
At the start of each file, in a comment, write down the names of your collaborators. For example:
# Problem Set 1A
# Name: Jane Lee
# Collaborators: John Doe
Please estimate the number of hours you spent on the Problem Set in the question box below.
Submit
Submit
5.3.2) Part B
Select File No file selected
Submit
5.3.3) Part C
Select File No file selected
Submit
6
MIT OpenCourseWare
https://ocw.mit.edu
For information about citing these materials or our Terms of Use, visit: https://ocw.mit.edu/terms