Exercise 66

Write a function in Python which takes as argument a tuple (a, b) composed of two integers and returns it the least common multiple LCM of a and b without using any predefined function in python.

Solution


def leastCommonMult(a,b):
# take m = a as initial value
m = a

# while m is not common multiple
while (m%a != 0 or m%b !=0):
# we incremente m
m = m + 1
return m

# testing function
print("The least common multiple of 6 and 9 is m = ",leastCommonMult(6 , 9))
#The out put is: The least common multiple of 6 and 9 is m = 18
Younes Derfoufi
my-courses.net

Leave a Reply