【发布时间】:2021-09-18 12:13:41
【问题描述】:
这是我写的代码,我无法得到预期的结果。 我总是得到一个重复 8 次的数量。
amount = float(input('the principal amount: '))
rate = float(input('annual rate of return: '))
time = int(input('how many years it will take: '))
def invest(amount, rate, time):
total = amount * (1+rate)**time
print(total)
for t in range(time):
total_new = amount * (1+rate)**time
print(total_new)
invest(amount, rate, time)
expected outpout for invest(100, 0.05, 8):
year1: $105
year2: $110.25
year3: $115.7625
.
.
.
.
.
year8: $147.745544379
【问题讨论】:
标签: python loops for-loop logic formula