Saint Louis University |
Computer Science 150
|
Dept. of Math & Computer Science |
For this assignment, you must work individually in regard to the design and implementation of your project.
Please make sure you adhere to the policies on academic integrity in this regard.
The interest calculator is an interactive program which prompts the user for an interest rate and a principal, then calculates and prints the balance that would be after one year.
For this project, in addition to producing the desired user interactions, we are requiring that your internal design make use of several functions, as defined later in this description.
This project also differs from earlier projects in that there is an increased focus on error checking. For past projects, we have allowed you to assume that all user input is valid. For this project, you must gracefully handle any input entered by the user.
This interest calculator will ask you to select an interest rate, followed by a principal value. It will then calculate and display the principal, interest rate, and balance after one year. You will then be invited to execute the process again or terminate. Please select an interest rate: A) 3% B) 5% C) 7% D) 10% Enter A-D: 5 That is not a valid selection. Please select an interest rate: A) 3% B) 5% C) 7% D) 10% Enter A-D: B Enter the principal: $100 Initial Principal Interest Rate End of Year Balance ========================================================= $100.00 0.05 $105.00 Another Computation [y/n]? y Please select an interest rate: A) 1% B) 5% C) 8% D) 10% E) 14% F) 19% Enter A-F: H That is not a valid selection. Please select an interest rate: A) 1% B) 5% C) 8% D) 10% E) 14% F) 19% Enter A-F: D Enter the principal: zero Please enter a number Enter the principal: -0.50 You must enter a positive amount. Enter the principal: 1000000 The principal must be less than $1 million. Enter the principal: $2500.925 The principal must be specified in dollars and cents. Enter the principal: 2500.93 Initial Principal Interest Rate End of Year Balance ========================================================= $2500.12 0.10 $2751.02 Another Computation [y/n]? n Quitting program. Bye.
This program is to use functions and do complete error checking and recovery.
Please note the following requirements:
Create a function greeting() that displays the initial text. This function should be called once, when the program begins.
Create a function getRate(choices) that manages the user interaction for selecting an interest rate from among a nonempty list of integer percentages.
from random import sample, randintThen you can generate a new list of choices to send as a parameter using the command
sorted(sample(range(1,20), randint(2,6)))
Create a function getPrincipal(limit) that collects and returns a floating point number from the user that represents the principal amount.
Create a function, computeBalance(principal, rate),
that calculates and returns the year-end balance given the
parameters.
Use the formula:
balance = principal + (principal * rate)
Create a function to display the results as shown in the example session:
display = '%.2f' % valueto generate a string representation of the floating-point value with two digits after the decimal point. (You can later print the display string as part of the output.)
For the "Another Principal" question, accept any line that has
either 'y' or 'Y' as the first non-blank character to indicate yes,
and any line that has either 'n' or 'N' as the first non-black
character to indicate no; any other response is
inconclusive in which case the questions should be repeated.
For example,
y Yes yahwould all be accepted to indicate yes.
Note that this functionality is very similar to the yesOrNo function that is described as exercise Practice 5.31 in the text (see solution in the appendix), except that our rule for what constitutes a yes or no is different.
You should create a file, named interest.py, that contains all of your own code. This file must be submitted electronically.
You should also submit a separate 'readme' text file, as outlined in the general webpage on programming assignments.
Please see details regarding the submission process from the general programming web page, as well as a discussion of the late policy.
The assignment is worth 10 points.
Rather than displaying only the end-of-year balance, display twelve monthly balances, assuming that interest is compounded monthly. Treat the indicated interest rate as an Annual Percentage Rate (APR). An effective monthly interest rate can be computed using the following formula in Python:
monthly = pow(1+annual, 1.0/12) - 1Applying that rate monthly should result in the same end-of-year balance as in the original computation.
Display your results as follows:
Month Starting Balance APR Ending Balance ================================================== Jan $100.00 0.05 $100.41 Feb $100.41 0.05 $100.82 Mar $100.82 0.05 $101.23 Apr $101.23 0.05 $101.64 May $101.64 0.05 $102.05 Jun $102.05 0.05 $102.47 Jul $102.47 0.05 $102.89 Aug $102.89 0.05 $103.31 Sep $103.31 0.05 $103.73 Oct $103.73 0.05 $104.15 Nov $104.15 0.05 $104.57 Dec $104.57 0.05 $105.00