Saint Louis University |
Computer Science 1300/5001
|
Computer Science Department |
For this assignment, you are allowed to work with one other student if you wish (in fact, we suggest that you do so). If any student wishes to have a partner but has not been able to locate one, please let the instructor know so that we can match up partners.
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: 1000001 The principal can be at most 10000000. 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.93 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 Computation" question, create a standalone
function, askYesNo(prompt) that
accepts 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 the only responsibilities for this function are the user interactions involved in determining whether to return True (for yes) or False (for no). The job of restarting the process should remain within the primary flow of the script.
The source code should be organized so that all of the funtion definitions are given at the beginning of the file, and all top-level code (i.e., that not within the body of a function) should be given at the end of the file (i.e., after all the functions have been defined).
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 40 points, apportioned as follows:
In addition to displaying the required 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:
Initial Principal Interest Rate End of Year Balance ======================================================= $950.00 0.12 $1064.00 Month Starting Balance APR Ending Balance ================================================== Jan $ 950.00 0.12 $ 959.01 Feb $ 959.01 0.12 $ 968.11 Mar $ 968.11 0.12 $ 977.30 Apr $ 977.30 0.12 $ 986.57 May $ 986.57 0.12 $ 995.94 Jun $ 995.94 0.12 $1005.39 Jul $1005.39 0.12 $1014.93 Aug $1014.93 0.12 $1024.56 Sep $1024.56 0.12 $1034.28 Oct $1034.28 0.12 $1044.09 Nov $1044.09 0.12 $1054.00 Dec $1054.00 0.12 $1064.00