(Very Newbie) Problems defining a variable
febaen at gmail.com
Fri Dec 12 13:58:36 CET 2008
Actually, I have gedit set to four spaces per tab. I have no reason
why it's showing up that large on copy/paste, but the file itself is
Thanks for the advice Chris, Stephen, I can definitely see how those
are both far better ways of doing it. I have it as:
bank = int(input("How much money is in your account?\n>>"))
if bank <=0:
print("You need a postive amount to gain interest.")
target = int(input("How much money would you like to earn each year?
interest = 0
i = 0
while interest < target:
#determine the interest rate to use
if bank >= 100000:
rate = 0.0173
elif bank >= 50000:
rate = 0.0149
elif bank >= 25000:
rate = 0.0124
elif bank >= 10000:
rate = 0.0085
rate = 0.0060
#Now that we know what interest rate to use, apply it...
lastbank = bank #To calculate interest...
bank += (bank * rate) #Update earnings...
interest = bank - lastbank #And figure out how much interest is made!
i += 1 #So we can see which year a calculation represents
print("Year %s, at %s rate: %s paid, %s in bank." % (i, rate,
now it checks to make sure the account is positive before moving on,
in addition to using your recommendations on readability and
efficiency in getting the rate
More information about the Python-list