I created a function to compute HCF of 2 numbers.When I used my parameters as 24 and 36,I am getting the correct answer but when I used the different numbers,I am getting an error : ValueError: max() arg is an empty sequence Here is the code:
def computeHCF(num1,num2):
lst1 = []
lst2 = []
for i in range(2,num1+1):
if i > 1:
if num1 % i == 0:
lst1.append(i)
for i in range(2,num2+1):
if i > 1:
if num2 % i == 0:
lst2.append(i)
HCF = []
for e1,e2 in zip(lst1,lst2):
if e1 == e2:
HCF.append(e1)
HCF = max(HCF)
print('The HCF is :',HCF)
I know there are other solutions to this but I tried implementing this method. Edit : Ignore the indentation here.I know where the logic is incorrect.