8000 Update solution to invest challenge · monkeyfx/python-basics-exercises@d98ce06 · GitHub
[go: up one dir, main page]

Skip to content

Commit d98ce06

Browse files
committed
Update solution to invest challenge
1 parent 34aaf92 com
8000
mit d98ce06

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

ch06-functions-and-loops/5-challenge.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44

55
# Calculate compound interest to track the growth of an investment
66

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):
7+
def invest(amount, rate, years):
8+
for year in range(1, years + 1):
129
amount = amount * (1 + rate)
13-
print(f"year {t}: ${amount:,.2f}")
14-
print()
10+
print(f"year {year}: ${amount:,.2f}")
11+
1512

13+
amount = float(input("Enter a principal amount: "))
14+
rate = float(input("Enter an anual rate of return: "))
15+
years = int(input("Enter a number of years: "))
1616

17-
invest(100, 0.05, 8)
18-
invest(2000, 0.025, 5)
17+
invest(amount, rate, years)

0 commit comments

Comments
 (0)
0