#4aa: Coding in Python {LCM Calculator}
- x=1
- while x!=0:
- howMany = int(input('Enter number of numbers: '))
- print()
- if howMany>1:
- x=0
- allNumbers = []
- for i in range(howMany):
- EN=('Enter number #{}: '.format(i+1))
- y=1
- while y!=0:
- number = int(input(EN))
- if number>1:
- y=0
- allNumbers.append(number)
- else:
- print('Retry, make sure that desired number is a natural number, i.e., more than 0.')
- print()
- #product
- product = 1
- for i in (allNumbers):
- product=product*i
- #collection
- bigList=[]
- for i in (allNumbers):
- for j in range (1,(int(product/i))+1):
- bigList.append(i*j)
- #filter
- for i in (bigList):
- if bigList.count(i)==howMany:
- print()
- print('Required LCM is',i)
- break
- else:
- print('Retry, choice should be more than 1.')
- print()
Download the above code from here.
Comments