我正在为一个comp-sci班做作业。我觉得我离得很近,但我不太明白答案。基本上,这项任务是一个复利计算器,我想做的是在初始投资中增加存款,允许有人在某个时候停止支付,但在另一个时候收回。例如,“用户可能已经
当他们开始计算退休时,在他们的帐户里存了1万美元。他们打算拯救
在接下来的10年里,他们每年将再支付1000美元,届时他们将不再额外支付
存入他们的帐户。然而,他们离退休还有20年的时间。你的程序
应该能够解释这些变化的输入,并计算其
的正确未来值
退休账户”
这是我目前的代码:def main():
print("Welcome to Letmeretire.com's financial retirement calculator!")
import random
num = random.randrange(10000)
principal = int(input("How much are you starting with for your retirement savings?"))
deposit = int(input("How much money do you plan to deposit each year?"))
interest = int(input("How much interest will your account accrue annually"))
time = int(input("Please enter the number of years that you plan to deposit money for."))
time_till_retirement = int(input("How long until you plan on retiring? (Please enter this amount in years)"))
t = time + 1
APR = interest/100
R = ((1+APR/12)**12)-1
DR = deposit/R
DRT = deposit/(R*(1+R)**time)
PV = principal+(DR-DRT)
future_value = PV*((1+APR/12)**12*time)
if time < time_till_retirement:
time1 = (time_till_retirement-time)
future = future_value*((1+APR/12)**12*time1)
else:
future = future_value
for i in range(1, t):
print("After " + str(i) + " years you will have "+ str(future) + " saved!")
main()
我希望输出如下:Enter annual deposit: 1000
Enter interest rate: 12
Enter number of years until retirement: 10
What's the current balance of your account: 5000
How many years will you make your annual deposit? 5
After 1 year, you have: $ 6720.0
After 2 years, you have: $ 8646.4
After 3 years, you have: $ 10803.97
After 4 years, you have: $ 13220.44
After 5 years, you have: $ 15926.9
After 6 years, you have: $ 17838.13
After 7 years, you have: $ 19978.7
After 8 years, you have: $ 22376.14
After 9 years, you have: $ 25061.28
After 10 years, you have: $ 28068.64
But what Im getting is this:
Welcome to Letmeretire.com's financial retirement calculator!
How much are you starting with for your retirement savings?5000
How much money do you plan to deposit each year?1000
How much interest will your account accrue annually12
Please enter the number of years that you plan to deposit money for.5
How long until you plan on retiring? (Please enter this amount in years)10
After 1 years you will have 271235.9643776919 saved!
After 2 years you will have 271235.9643776919 saved!
After 3 years you will have 271235.9643776919 saved!
After 4 years you will have 271235.9643776919 saved!
After 5 years you will have 271235.9643776919 saved!