Exhaustive Unit Testing

Terry Reedy tjreedy at udel.edu
Sun Nov 30 01:11:48 EST 2008


Steven D'Aprano wrote:
> On Sun, 30 Nov 2008 03:42:50 +0000, Steven D'Aprano wrote:
> 
>> def lcm(a, b):
>>     return a/gcd(a, b)*b
>>
>> (By the way: there's a subtle bug in lcm() that will hit you in Python 
> 3. Can you spot it?
> 
> Er, ignore this. Division in Python 3 only returns a float if the 
> remainder is non-zero, and when dividing by the gcd the remainder should 
> always be zero.

You were right the first time.
IDLE 3.0rc3
 >>> a = 4/2
 >>> a
2.0

lcm should return an int so should be written a//gcd(a,b) * b
to guarantee that.




More information about the Python-list mailing list