Search for question

Section 1 Essential concepts and skills

Exercise 3-3

Enhance the Future Value program

In this exercise, you'll enhance the Future Value program so the console display

looks something like this:

Welcome to the Future Value Calculator

Enter monthly investment:

Entry must be greater than 0.

Enter monthly investment:

Enter yearly interest rate:

Entry must be greater than 0

Please try again.

Enter yearly interest rate:

Enter number of years:

Entry must be greater than 0

Please try again.

Enter number of years:

Year 1 Future Value -

Year - 2

Future Value -

Year

3

Year

Future Value =

Future Value -

Future Value -

Future Value -

Future Value -

Future Value -

0

Please try again.

100

16

and less than or equal to 15.

9 Future Value -

10 Future Value -

12

100

and less than or equal to 50.

10

1280.93

2724.32

Year - 5

Year - 6

Year 7

Year 8

Year

Year -

Continue (y/n)? n

1. In IDLE, open the future_value.py file that's in this folder:

marach/python/exercises/ch03

2. Test the program, but remember that it doesn't do any validation so enter valid

numbers.

4350.76

6183.48

8248.64

10575.7

13197.9

16152.66

19482.15

23233.91

3. Add data validation for the monthly investment entry. Use a while loop to

check the validity of the entry and keep looping until the entry is valid. To

be valid, the investment amount must be greater than zero. If it isn't, an error

message like the first one shown above should be displayed.

4. Use the same technique to add data validation for the interest rate and years.

The interest rate must be greater than zero and less than or equal to 15. And

the years must be greater than zero and less than or equal to 50. For each

invalid entry, display an appropriate error message. When you're finished,

you'll have three while loops and a for loop nested within an outer while loop.

5. Modify the statements in the for loop that calculates the future value so one

line is displayed for each year that shows the year number and future value, as

shown above. To do that, you need to work with the integer that's returned by

the range() function.

Fig: 1