Exhaustive Unit Testing
tjreedy at udel.edu
Sun Nov 30 07:11:48 CET 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.
>>> a = 4/2
lcm should return an int so should be written a//gcd(a,b) * b
to guarantee that.
More information about the Python-list