def main():

    goal, apr, deposit = getSavingsDetails()
    determineMonthsTilSaved( goal, apr, deposit )

    months = determineMonthsTilSaved(goal, apr, deposit)

    summarize( months )

def getSavingsDetails():
    """
    goal = float( input( "Principal sought? $" ) )
    apr = float( input( "Interest rate? " ) )
    deposit = float( input( "Deposit? $" ) )
    """
    goal = 1000.0
    apr = .05
    deposit = 100
    return goal, apr, deposit

def determineMonthsTilSaved( goal, apr, deposit ):
    months = 0
    saved = 0
    totalInterest = 0.0




    while saved < goal:
        interest = saved * apr / 12
        totalInterest += interest
        saved += (deposit + interest)
        months += 1
        print( months, ("%.2f" % saved), ("%.2f" % totalInterest) )

    return months

def summarize( months ):
    print( "Saved! It took ", months // 12, "years and", months % 12,
"months." )

main()


When this is run it appears that determineMonthsTilSaved is running twice
before the loop ends.  It is supposed to run until saved > than goal, but
look at the output.  It runs again even after saved > goal.  Help please?
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to