In this assignment, you will continue your practice writing interactive programs. You may work alone or with a partner of your choice. You will have an opportunity to find a partner during class on Friday.
Precondition: Obtain the homework template
At the top of every Python file you create in homework for this course, include the following text:
Fill in the correct information before you get started. This will be a precondition for every assignment where you program in Python.
Handling customer requests
As in the previous assignment, I would like you to ...
- Look at the two customer requests below.
- Analyze each request and design an algorithm to solve to the problem.
- After you have studied the problems and designed your algorithms, you should write a program to solve each of the problems.
- Once you think you have the code working, TEST it thoroughly. Don't simply run it once with one set of values and assume it is good. Test it with three to five different values (or sets of values, actually) and make sure that the numbers the computer gives you agree with the numbers you know to be true or have calculated "by hand". If you find examples that prove your code incorrect, it's your responsibility to fix your solution or report honestly on any problems you discovered but could not fix. You will later reflect on your approach to debugging.
Note that these steps are iterative. As long as your program has bugs, you may need to rewrite your code, reconsider your design, reconsider the problem, or ask more questions about what the customer wants.
Request 1: Compound interest (interest.py)
You are contacted by Dr. Jan Crouter who is the chair of the Economics department at Whitman College. Her department has a new professor of finance. The new professor will need a general tool that their students can use to compute compound interest.
Dr. Crouter tells you the program should take the following inputs from the user:
- Principal amount (initial investment);
- Annual nominal interest rate (as a decimal);
- Number of times the interest is compounded per year;
- Number of years.
The program should calculate and print the final amount of the investment, with interest, after the specified number of years have elapsed.
Note: Your program should ask for the inputs in the order specified. Failure to following this ordering will result in some point deduction.
Hint: The formula for computing compound interest is given in exercise 2.4.4. We wrote a solution for a special case of this problem in class.
Request 2: An interesting story (madlibs.py)
I think Mad Libs™ are hilarious. Please write me a Mad Lib similar to the one in exercise 2.4.13. Your program should request at least five words from the user.
If you adapt a story from another source, make sure to cite that source in a comment in your program. Comments are meant for humans to read; the computer ignores them. In Python, comments look like this:
# This is a short comment.
This is a long ...
... long ...
... long comment.
You will learn more about comments next week.
Of course, you are welcome to write your own story from scratch.
Submitting your work
Submit two files,
madlibs.py, to this assignment on Canvas. If you work with a partner, please submit a single solution that has both your names on it.
Again, if you have any problems here, don't hesitate to ask your professor, or the lab aides or class mentors.
Janet Davis (firstname.lastname@example.org) Thanks to Jan Crouter for humoring us.
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.