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
10.1. FAQs¶
- Helps us build the correct product without waste or redundancy
- It often makes sense to write the test first and then write as much code as necessary to allow the test to pass.
- Makes the code run faster.
- This is incorrect because defining tests doesn't directly affect the speed of the code.
- Allows the programmer to write less code.
- This is incorrect because writing tests actually requires writing more code.
- Not necessary for good programming.
- This is incorrect because defining tests is an important aspect of good programming practices.
Q-2: Why is defining some tests before implementation a good programming practice?
- Allows testing of the program's logical flow before coding it.
- Writing pseudocode in the design stage provides several benefits, including the ability to test the logic and structure of the program before writing any actual code.
- Saves time and effort in later coding.
- This is incorrect because writing pseudocode requires time and effort, but it's an investment that's worth it in the design stage.
- Helps identify syntax errors in the code.
- This helps identify logical errors, gaps, and loopholes in the program design, which saves time and effort in the long run.
- Facilitates code debugging.
- This helps identify logical errors, gaps, and loopholes in the program design, which saves time and effort in the long run.
Q-3: What is the advantage of writing pseudocode in the design stage?