[Tutor] LCM

Selby Rowley Cannon selbyrowleycannon at ymail.com
Wed Nov 14 18:52:03 CET 2012


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]


More information about the Tutor mailing list