1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2013
Posts
4
Rep Power
0

#### Retirement Calculator Fail

Hello all,

I'm trying to create a calculator that will tell the user how many years it will take to become a millionaire based on deposit information. Everything runs and works as intended, except for the years value of yearsMillion at the very end.

Code:
```#Assign the initial values
balance = float(input("What is your starting balance?"))
deposit = float(input("Your monthly deposit amount?"))
rate = float(input("What is your interest rate?")) / 100.0 / 12.0
years = int(input("Over how many years?"))
yearsMillion = 0
balance1 = balance
#Calculate retirement fund in years using nested loops
print "Fund by years (" + str(rate*12*100) + "% annual interest rate)"
print "Year\tFund"
for y in range(0,years):
for m in range(0,12):
balance = (balance+deposit)*(1+rate)
print str(y+1) + "\t\${:,.2f}".format(balance)
#Display the result
print "Retirement Funds: \${:,.2f}".format(balance)
when = raw_input("Do you want to know when you will become a Millionaire? (y/n)")
print "it works"

#Calculate the millionaire length
if when == "y":
print "it works too"
for y in range(0,yearsMillion):
for g in range(balance1,10000000):
for m in range(0,12):
balance1 = (balance1+deposit)*(1+rate)
yearsMillion +=1

print "You will be a millionaire in ", yearsMillion, " years!"
else:
print "Thank you anyway!  Goodbye!"```
I'm basing all of my logic and structure from my limited C++ experience. This is my first real attempt at a python program. Thanks in advance!
2. When you have:
for y in range(0,yearsMillion):
The value of yearsMillion is zero.
Better to have
while balance1<1000000:
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Sep 2013
Posts
4
Rep Power
0
I knew it was something simple.

Thank you rrashkin!!