Reputation: 11
I'm trying to get this homework done for class and no matter what I do, it freezes at the while loop. Everything seems correct to me but I am also pretty new to python. Any help would be appreciated.
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.")
Upvotes: 1
Views: 434
Reputation: 2777
You are never changing the value of retire or expenses within the body of the loop.
Upvotes: 0
Reputation: 39013
Well, you're not changing retire
or expenses
in the loop, so once you enter the loop, you never leave.
Move the statement retire = totalAmount * monthlyWidthdraw
into the loop.
Upvotes: 2