我正在尝试为课堂完成这项功课,无论我做什么,它都会在while循环中冻结。对我来说一切似乎都是对的,但我对python也很陌生。任何帮助将不胜感激。
print("This program will tell you how long it will take you to retire.")
yearlyReturns = float(input("Enter your yearly investment returns (est .05): "))
monthlyWithdraw = float(input("Enter percentage of your savings you will withdraw monthly (est .04): "))
income = float(input("Enter your monthly income: "))
percentSavings = float(input("Enter the percent of your income you save per month: "))
monthlySavings = (income * percentSavings)
expenses = (income - monthlySavings)
expensesTotal = (expenses * 12)
yearlyReturns = (yearlyReturns / 12)
totalAmount = (yearlyReturns * monthlySavings)
retire = (totalAmount * monthlyWithdraw)
months = 0
while retire < expenses:
totalAmount = (totalAmount + monthlySavings)
totalAmount = (totalAmount * yearlyReturns)
months = months + 1
years = (months / 12)
print(income)
print(expenses)
print(monthlySavings)
print("It took ",months," to save enough to retire.")
print("That will be ",years," years.")
print("See what saving a little bit more would do.")
答案 0 :(得分:2)
嗯,你没有在循环中更改retire
或expenses
,所以一旦你进入循环,就永远不会离开。
将语句retire = totalAmount * monthlyWidthdraw
移动到循环中。
答案 1 :(得分:0)
您永远不会在循环体内更改退休或费用的值。