We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 34aaf92 commit d98ce06Copy full SHA for d98ce06
ch06-functions-and-loops/5-challenge.py
@@ -4,15 +4,14 @@
4
5
# Calculate compound interest to track the growth of an investment
6
7
-
8
-def invest(amount, rate, time):
9
- print(f"principal amount: ${amount}")
10
- print("annual rate of return:", rate)
11
- for t in range(1, time + 1):
+def invest(amount, rate, years):
+ for year in range(1, years + 1):
12
amount = amount * (1 + rate)
13
- print(f"year {t}: ${amount:,.2f}")
14
- print()
+ print(f"year {year}: ${amount:,.2f}")
+
15
+amount = float(input("Enter a principal amount: "))
+rate = float(input("Enter an anual rate of return: "))
+years = int(input("Enter a number of years: "))
16
17
-invest(100, 0.05, 8)
18
-invest(2000, 0.025, 5)
+invest(amount, rate, years)
0 commit comments