-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFind_HCF.py
32 lines (27 loc) · 911 Bytes
/
Find_HCF.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
# Python Program to Find HCF of numbers of a list
def find_hcf(list):
def elementsOfSpecificCount(factors,lengthOfMainList):
listWithSimilarCounts = []
for i in range(0,len(factors)):
if factors.count(factors[i])==lengthOfMainList:
listWithSimilarCounts.append(factors[i])
return listWithSimilarCounts
def findFactors(number):
factors = []
for i in range(1, number + 1):
if number % i == 0:
factors.append(i)
return factors
lengthOfList = len(list)
all_factors = []
for i in range(0, lengthOfList):
k = 0
while k<len(findFactors(list[i])):
all_factors.append(findFactors(list[i])[k])
k=k+1
temp = []
temp = elementsOfSpecificCount(all_factors,lengthOfList)
temp.sort()
return temp[len(temp)-1]
l = [24, 54]
print(find_hcf(l))