[Tutor] LCM

Dave Angel d at davea.name
Wed Nov 14 19:27:28 CET 2012


On 11/14/2012 12:52 PM, Selby Rowley Cannon 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-process end of things. Anyone mind looking at
> it, and tell me what's wrong? (I hop you don't think it's too long to
> put in an email)
>
> Code:
>
> def lowestCommonMultiple(a, b, amount): #k
>     float(amount)
>     if a == b:
>         print 'You cannot find the LCM of the same number twice.'
>     else:
>         numbersList = list(range(amount))
>         aMultiples = []
>         bMultiples = []
>         for aNumber in numbersList:
>             aMultiples.append(a*aNumber)
>         for bNumber in numbersList:
>             bMultiples.append(b*bNumber)
>         if aMultiples[1] == bMultiples[1]:
>             print 'The LCM of ', a, ' and ', b, ' is ', aMultiple[1]

Which are you interested in, finding what's wrong with the code, or a
simpler way to actually find an LCM ?

Is this an assignment, or just part of a bigger program you're writing?

-- 
DaveA


More information about the Tutor mailing list