[Tutor] assert() question
Alan Gauld
alan.gauld at btinternet.com
Sun Jul 6 15:01:25 CEST 2008
"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.
Alan G.
More information about the Tutor
mailing list