Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Challenge: Track Your Investment

00:00 Now the final challenge of this course. This challenge will combine parts of the exercises you had in this course and merge them into one big challenge that you can separate into smaller tasks.

00:16 Write a program called invest.py that tracks the growing amount of investment over time.

00:23 The initial deposit for an investment is called the principal amount. Each year the amount increases by a fixed percentage called the annual rate of return.

00:35 For example, a principal amount of a hundred dollars with an annual rate of return of 5 percent increases the first year by $5 for a new amount of $105. The second year, the increase is 5% of $105, or $5.25, bringing the total to $110.25.

01:00 So this might be a bit confusing for now. Let me continue with what the challenge is, and hopefully things will be a bit clearer then. In your program, invest.py, write a function called invest() with three parameters: the principal amount, the annual rate of return, and the number of years.

01:20 To calculate the function signature might look something like this: def invest(amount, rate, years): and then closing it. The function should then print out the amount of the investment rounded to two decimal places at the end of each year for the specified number of years.

01:42 Coming back to the example I mentioned before, when you call the invest() function with 100 and .05 and 4, your program should print the following output: year one: $105 year 2: $110.25 year 3: $115.76 year 4: $121.55.

02:10 So it’s each time rounded to two decimal places. So the first year is $105.00.

02:20 To finish the program, prompt the user to enter an initial amount, an annual percentage rate, and the number of years, and then call invest() to display the calculations for the values entered by the user.

02:35 Take all the time you need to solve this challenge. And once you’re ready, you can continue with the next lesson, where I tackle the challenge myself, and then you can compare your solution to mine.

Become a Member to join the conversation.