Você está na página 1de 4

Programming Project #1

INF 120
Due Date: As posted in Blackboard

Instructor: Ryan Lehan

This is an individual assignment.


Name your file(s) exactly as directed in the instructions.
Submit a Python (JES) program named Project1_LastName_FirstName.py that calculates the
future value of an investment given an initial investment amount, an annual interest rate, and a
holding period (term) of a number of years. Read this entire document before attempting the
design or implementation.

Requirements
R1. For this and all programming projects, provide a preamble with the course/section, program
name, your first and last name, and the date you completed the coding and testing (10 points):
# INF 120 <Section>
# Project 1
# <FirstName LastName>
# <Date completed>

R2. The three values required to calculate future value are obtained as user inputs
with appropriately descriptive prompts and are stored as variables. (30 points):
1) The initial investment amount is to be entered as a floating point number with two decimal
places, e.g., 1000.00
2) The annual interest rate is to be entered as a floating point number with at least one
decimal place (e.g., 3.5 to represent 3.5%, 3.0 to represent 3%, or 4.25 to represent 4.25%)
3) The period for which the investment is held is to be entered as a whole number, e.g., 5
for five years, 3 for three years, etc.
R3: Future investment value is calculated using the following formula (10 points):

fv = i * (1 + m)

(t * 12)

Where fv is future value, i is the initial investment amount, m is the monthly interest rate, and t
is the term (investment period) in years.

To translate this formula into a Python statement, we use the exponent operator. 10 is
expressed in Python as 10 ** 2.
th

The monthly interest rate is 1/12 of the annual rate, and we have to convert it to an amount <
1 to get the correct end result. Rather than prompt the user for the monthly interest rate, we will
calculate it on the fly using the following Python statement, where a is the annual interest rate.

fv = i * ( 1 + a / 1200 ) ** (t * 12)
R4. Your program must use variable names that are more descriptive than the 1-2 letter names
given. For example, fv might become futureValue or future_value. Observe Python variable
naming rules and use a mixture of upper and lower case letters (or underscores) to
differentiate individual words that might make up one variable name. (15 points)
R5. The program will then display the future investment value in a dialog box with explanatory
text. For example, if the calculated amount is 1105.0789265308222, the message in the dialog
box should read:
The future investment value is: $1105.0789265308222 (20 points)
NOTE: In order to concatenate the numeric value representing the future value with the string
The future investment value is: $, we have to use a function that is introduced in Chapter 3
called str(). Assume n is the value 11.0. To create a string "The value of n is 11.0" the syntax is
"The value of n is " + str( n ). [str( n ) converts the parameter n to its string equivalent.]

R6. Submit only your .py file, named as specified above, to the BlackBoard drop box associated
with Project 1 (15 points).

TESTING HINT: Once you have verified that you can obtain and store the 3 user input values
in the correct format, you might want to use the technique illustrated in the code example
YellowWindow.py (in Blackboard under Module 1 Code Examples Chapter 2) to
streamline testing. That technique is to temporarily comment out the statements that obtain user
input and substitute simple assignment statements that allow you to quickly plug in values for
testing.

Extra credit
(5 additional points awarded for each item implemented successfully)
1) The future investment amount may come out to be a number such as 1190.942829142895.
Python (and thus JES) has a function called round() that returns the floating point value
rounded to a specified number of digits after the decimal point. Use online resources to

look up the use of the function and format the output to display no more than two decimal
places. For example, the output would be 1190.94 for the raw value 1190.942829142895.
[If the rounded amount happens to contain only one decimal place, as it would for the raw
value 1133.0011218785867, you do not have to force it to display 1133.00. The function
only guarantees that the result will have no more than the specified number of decimal
places.]
2) One way to reduce the annual interest rate to a monthly interest rate is to divide the
annual rate by 1200, i/1200 in the Python statement given above. There is a potential
problem with this approach if the annual interest rate were to be stored as an integer.
Test your program by assigning a whole number for the interest rate to override what
the user entered, and you will find that the monthly interest rate becomes zero. [This is a
preview of a topic covered in Chapter 4 and it has to do with the way Python performs
integer division.] Rewrite the formula such that we get the correct result if 2 is entered
instead of 2.0 for 2%, 3 instead of 3.0 for 3%, etc.
HINT: Use multiplication rather than division.
3) Sometimes we introduce temporary variables to make the program logic clearer. This
program might benefit from a temporary variable that represents the monthly interest rate.
The Python statement that calculates future value could then use the monthly interest rate
directly. Devise a descriptive name for m, calculate and store it, and use it in the final
calculation in place of i/1200:
fv= i * ( 1 + m ) ** (t * 12)

Sample Run
Inputs:

Output:

With Extra Credit item #1:

Você também pode gostar