Saturday, March 2, 2019

Hamming Distance - Computer Networks | Python3

a=str(input('Enter the 1st binary number: '))
b=str(input('Enter the 2nd binary number: '))

def hamming_distance(a, b): 
    distance = 0
    
    if(len(a) != len(b)):
        print('Invalid! Check the length')
    else: 
        for i in range(len(a)):
            if a[i] != b[i]:
                distance += 1
        return distance

print('Hamming Distance: ',hamming_distance(a, b))

ScreenShot:



No comments:

Post a Comment