10. Exercise¶
We want to develop a program that determines the future value of an investment, given the initial value and the interest rate
We follow the steps for development.
- Analysis:
The initial money generates an annual interest rate
How much will it be worth in 10 years?
Input: initial amount, interest rate
Output: value in 10 years
- Specification:
The user enters the initial amount invested
The user enters the annual interest rate
Value of the financial mathematical formula * (1 + interest)
- Design:
Enter the initial investment amount.
Enter the interest rate.
- Repeat 10 times:
initial value = initial value * (1 + interest rate)
Print the updated value.
- Implementation:
- Test values:
1000 dollars investment and 3% annual interest rate
1000 dollars investment and 10% annual interest rate
value = float(input("Initial amount invested: "))
rate = float(input("Annual interest rate: "))
for i in range(10):
value = value * (1 + rate / 100)
print("Value after 10 years: %5.2f" % value)
Activity: 10.1 ActiveCode (ac_l40_10_en)
10.1. FAQs¶
Q-2: Why is defining some tests before implementation a good programming practice?
Activity: 10.1.1 Multiple Choice (feedback_l40_10_1_en)
Q-3: What is the advantage of writing pseudocode in the design stage?
Activity: 10.1.2 Multiple Choice (feedback_l40_10_2_en)