Please Help Explain
Stan Graves
soundinmotiondj at yahoo.com
Thu Nov 6 14:42:58 EST 2003
"Jakle" <jakle1 at hotmail.com> wrote in message news:<lIjqb.2510$gn1.317177 at news1.news.adelphia.net>...
> +++++++++++++++++++++++++++++++++++++++
> # penny.py 11-05-03
>
> days = raw_input("How many days: ")
>
> def calc(n, days):
> i = 1
> while i <= days:
> n = n*2
> i = i+1
> return n/float(100)
Technically, the return should be:
return (n-1)/float(100)
The point is to sum the total, and your method over estimates the sum
by 1. You can verify this by running the program for 2 days and
looking at the total.
If the pay is one penny on the first day, and two pennies on the
second day - the the sum at the end of two days is 3 cents...not four
cents as suggested by the above code.
--Stan Graves
stan at SoundInMotionDJ.com
http://www.SoundInMotionDJ.com
>
> print calc(1, int(days))
> +++++++++++++++++++++++++++++++++++++++
More information about the Python-list
mailing list