lcm_main.py
#!/usr/bin/env python3 from lcm import * def main(): L = LCM(16, 24) print(L.lcm.__doc__) L.lcm() if __name__ == '__main__': main()
lcm.py
#!/usr/bin/env/ python3 class LCM: def __init__(self, x, y): self.x = x self.y = y def lcm(self): ''' DOC: LCM is a smallest number that is divisible by both numbers (or all). how we can find lcm of two numbers in python.''' print("") larger_number = 0 if self.x > self.y: larger_number = self.x else: larger_number = self.y while(True): if (larger_number % self.x == 0) and (larger_number % self.y == 0): lcm = larger_number break larger_number += 1 print("The Least Common Mulitple of {} and {} is {}".format(self.x, self.y, larger_number))
DOC: LCM is a smallest number that is divisible by both numbers (or all). how we can find lcm of two numbers in python. The Least Common Mulitple of 16 and 24 is 48