-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFind_LCM.py
37 lines (31 loc) · 897 Bytes
/
Find_LCM.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Python Program to Find LCM of a list of numbers
def find_lcm(list):
def numberOfSuccessfulDivision(list1):
list1.sort()
count = 0
largest = list1[-1]
for i in range(0, len(list1)):
if largest % list1[i] == 0:
count += 1
return count
list.sort()
length = len(list)
l = list[-1]
counter=2
count = numberOfSuccessfulDivision(list)
if count == length:
print("LCM = ", list[-1])
elif count < length:
while count != length:
list.pop()
p = l*counter
counter=counter+1
list.append(p)
count = numberOfSuccessfulDivision(list)
print("LCM = ", p)
n = int(input("How many numbers you want to enter? = "))
l = []
for i in range(0,n):
el = int(input("Enter number {0} = ".format(i+1)))
l.append(el)
find_lcm(l)