#4aa: Coding in Python {LCM Calculator}



  1. x=1
  2. while x!=0:
  3.     howMany = int(input('Enter number of numbers: '))
  4.     print()
  5.     if howMany>1:
  6.         x=0
  7.         allNumbers = []
  8.         for i in range(howMany):
  9.             EN=('Enter number #{}: '.format(i+1))
  10.             y=1
  11.             while y!=0:                
  12.                 number = int(input(EN))
  13.                 if number>1:
  14.                     y=0
  15.                     allNumbers.append(number)
  16.                 else:
  17.                     print('Retry, make sure that desired number is a natural number, i.e., more than 0.')
  18.                     print()
  19.         #product
  20.         product = 1
  21.         for i in (allNumbers):
  22.                 product=product*i
  23.         #collection   
  24.         bigList=[]
  25.         for i in (allNumbers):
  26.             for j in range (1,(int(product/i))+1):
  27.                 bigList.append(i*j)      
  28.         #filter
  29.         for i in (bigList):
  30.             if bigList.count(i)==howMany: 
  31.                 print()
  32.                 print('Required LCM is',i)
  33.                 break 
  34.     else:
  35.         print('Retry, choice should be more than 1.')
  36.         print()
Download the above code from here.

Comments