On 11/18/2012 12:50 PM, Andrew wrote:
> On Wed, 14 Nov 2012 19:52:03 +0200, Selby Rowley Cannon
> <selbyrowleycan...@ymail.com> wrote:
>
>> Hey,
>>
>>      I've been trying to write a function to find the Lowest Common
>> Multiple of two numbers, but it isn't working and I've kinda hit a
>> dead end on the thought-  <snip>

>> I have script I wonder if it would be suitable:
>
>
> def LCM(x,y):
>     for n in range(1, 10000):
>         for n2 in range(1, 10000):
>             x_lcm = x*n
>             y_lcm = y*n2
>             if x_lcm == y_lcm:
>                 print"The LCM of",x,"and",y,"is",x_lcm
>                 return x_lcm
>             else:
>                 pass
>

That won't usually provide the LCM, it'll  just provide some common
multiple.  Occasionally, it'll happen to be right.

Rather than returning the first value that's equal, you'd have to return
the lowest value that's equal.

-- 

DaveA

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to