0% found this document useful (0 votes)
9 views6 pages

Coding - Part 5 - CYU

Uploaded by

Dhaval Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Coding - Part 5 - CYU

Uploaded by

Dhaval Patel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CODING – PART 5

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

LEARNING GOALS AND SKILL DEVELOPMENT:


You know you have met the goals for this lesson when you can:

ANCHOR SKILL BUILDING


LEARNING GOALS
QUESTIONS QUESTIONS
Explain the purpose of a program created for a financial
1 1
application
EMERGING

Predict the output of a program created for a financial


1
application

ANCHOR SKILL BUILDING


LEARNING GOALS
QUESTIONS QUESTIONS
Modify a program created for a financial application and use it
2 2
to solve a problem
EVOLVING

ANCHOR SKILL BUILDING


LEARNING GOALS
QUESTIONS QUESTIONS
Write a program for a financial application, including at least
3 3
one conditional statement and at least one loop
EXTENDING

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

• 500 for principal


• 3 for rate_percent Set value = principal
• 10 for years
c) In order for the program to run without Start loop
error, what data type must be used for the
Repeat years times.
years variable? Explain.
d) Create the program in Python.
Set value = value + principal*rate
e) Run your Python program using the
following values:
• 1000 for principal End loop
• 2.3 for rate_percent
• 5 for years
Print value rounded to two decimal places
State the program’s output value and
interepret the meaning of the result.
f) Show how you could modify this program such that it does not require the use of a loop.

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

Set rate = rate_percent/100

Set value = principal + principal*rate*years

Print value rounded to two decimal places

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

Set rate = rate_percent/100

Set value = principal*(1+rate)years

Print value rounded to two decimal places

Coding – Part 5
ANSWERS 3. Answers may vary. For example,

or

Coding – Part 5

You might also like