Coding - Part 5 - CYU
Coding - Part 5 - CYU
BIG IDEAS:
• Coding can be used for quickly performing calculations involving interest
• Coding can be a useful tool for analyzing situations in personal finance and
informing decisions
Coding – Part 5
BUILD YOUR SKILLS
1. Study the program shown on the right. Read principal, rate_percent, and years
from user
a) Explain the purpose of the program.
b) Predict the program’s output when the
user inputs the following values: Set rate = rate_percent/100
2. The program shown in question #1 can be easily modified to use compound interest instead of
simple interest.
a) What single change can be made to the program to adapt it to a compound interest model?
b) Create the compound interest version of the program in Python.
c) Run your Python program from part (b) using the following values:
• 1000 for principal
• 2.3 for rate_percent
• 5 for years
State the program’s output value and interpret the meaning of the result. How
does this result compare to the simple interest result in question #1(e)?
d) Explain how you could modify your program from part (b) so that it
does not require the use of a loop.
Coding – Part 5
3. Create a program in Python that shows the amount money at the
end of each year in an account that earns compound interest
annually. Design your program such that the user first selects the
type of interest (simple or compound) and then enters the
principal, annual interest rate (as a percent), and number of years.
The output of the program should display all of the year numbers
(0, 1, 2, 3, …) and the corresponding amounts in the account.
Coding – Part 5
CHECK YOUR UNDERSTANDING
1. a) The program calculates the final amount of a principal value that earns simple interest. The
principal, annual interest rate, and number of years are entered by the user.
b) 650
c) Integer. The variable years is used to determine the number of times the loop repeats, which
can only be done using an integer value.
d)
ANSWERS
e) 1115.0, which means that if a principal of $1000 earns simple interest annually at a rate of
2.3%/year, the final amount after 5 years will be $1115.
f) Read principal, rate_percent, and years from user
Coding – Part 5
2. a) The calculation within the loop could be changed to value = value + value*rate so that the
interest is always calculated on the final amount from the previous year.
b)
ANSWERS
c) 1120.41, which means that if a principal of $1000 earns compound interest annually at a rate
of 2.3%/year, the final amount after 5 years will be $1120.41. This result is greater than the
simple interest result in question #1(e) by $5.41.
d) Read principal, rate_percent, and years from user
Coding – Part 5
ANSWERS 3. Answers may vary. For example,
or
Coding – Part 5