[Tutor] assert() question
Dick Moores
rdm at rcblue.com
Sun Jul 6 16:50:31 CEST 2008
At 06:01 AM 7/6/2008, Alan Gauld wrote:
>"Dick Moores" <rdm at rcblue.com> wrote
>>Traceback (most recent call last):
>> File "E:\PythonWork\Untitled 2.py", line 42, in <module>
>> assert(fact(10,4) == 3.629e+6)
>>AssertionError
>
>I'm not sure but I suspect you are running into the dreaded floating
>point precision problem.
>
>You probably need to try:
>
>result = 3.694e+6
>e = result/1000000 # add zeros to suit!
>assert(result - e < fact(10,4) < result + e)
>
>Or somesuch
>
>Just a guess though.
And a good one!
assert(result - e < fact(10,4) < result + e)
works with e = result/100000 but not with e = result/1000000 .
Thanks, Alan.
Dick
More information about the Tutor
mailing list