[Tutor] Is this correct?
bob gailer
bgailer at gmail.com
Mon Feb 9 03:29:46 CET 2009
Please always reply-all so a copy goes to the list. We all participate
and learn.
Would you also respond to my requests for clarified algorithm?
cclpianos at comcast.net wrote:
> Hi Bob,
>
> Thanks for your input! I ran the program in IDLE and it worked just
> fine. Apparently my calculations were correct, although sloppy. Some
> very good points for me to consider;
Thanks for the acknowledgment.
>
> Indentation. I felt for myself it was a bit more readable, but
> considering I'm new and the formatting may not survive other OS's, I
> plan on making those changes.
> The use of the 1.041 for the interest rate. Here, as I'm not
> mathematically inclined I don't see the advantages, but I'll compare
> the program to yours to see how it works.
Your calculation was, in effect, principal = principal + principal *
interest. Do you recall factoring in algebra?
principal = principal * (1 + interest). For me it is a little easier on
the eyes and thinking to see the latter.
You could also do:
principal += principal * interest
> Starting the count at 2 and eliminating the other if statements is a
> great simplification.
> It all seems a bit clearer in your rendition.
>
> Thanks again,
> Pat
>
> On Feb 8, 2009, at 3:11 PM, bob gailer wrote:
>
>> principal = balance = 500000 # Starting fund amount.
>> interestRate = .05 # Interest rate added to the principal annually.
>> tuition = 34986 # Starting tuition fee
>> tuitionInc = 1.041 # The annual increase applied to the tuition.
>> print principal, "Is the starting principal" # This is to show the
>> starting balance.
>> print tuition, "Is the starting tuition."
>> balance = principal - tuition
>> print balance," the amount remaining after first tuition deduction. "
>> interest = balance * interestRate # calculates the amount added to
>> the fund
>> print interest, " Interest added to fund for one year. "
>> newBalance = balance + interest
>> print newBalance, "is the new balance."
>> count = 2 # keeps me informed on the number of students benefitting
>> from this grant.
>> while principal > tuition:
>> tuition *= tuitionInc # calculates the rising cost of tuition.
>> if newBalance < tuition:
>> print newBalance + interest
>> newBalance = principal
>> print principal," is the new balance. "
>> interest = principal * interestRate
>> print interest," is the new interest on the principal. "
>> balance = principal + interest
>> print balance,"is the new principal. "
>> tuition *= tuitionInc # calculates the rising cost of tuition.
>> print tuition," is the new cost of tuition. "
>> principal = newBalance - tuition
>> print principal," is the new balance. "
>> interest = principal * interestRate
>> print interest," is the new interest on the principal. "
>> balance = principal + interest
>> print balance, "is the new principal. "
>> count = count + 1
>> if tuition > principal:
>> print principal + interest, "was available for the last student."
>> if count > 10:
>> print count, "Students used this grant."
>
--
Bob Gailer
Chapel Hill NC
919-636-4239
More information about the Tutor
mailing list