My code is trying to compare each separate character in a string to find the differences between two words. However, the line "if a[i] == b [i]" appears to be giving some grief. i is a variable which has already been given a value, and will be tracked through, and I cannot see how it is not running. My code in full is as follows:
a = str(input("Choose a word, any word: "))
b = str(input("Choose another word: "))
j = 0
r = 0
n = len(a)
m = len(b)
if n == m:
while r <= n:
if a[r] == b[r]:
r = r + 1
else:
j = j + 1
r = r + 1
print("The hamming distance between ", a, "and ", b, "is: ", j)
else:
p = max(n, m) - min(n, m)
while r <= p:
if a[r] == b[r]:
r = r + 1
else:
j = j + 1
r = r + 1
k = p + j
print ("The hamming distance between ", a, "and ", b, "is: ", k)
I know it likely isnt the most compact, but any help would be greatly appreciated, thank you.
Edit: I have fixed it, sheer stupidity on my part, a simple case of removing the equal from after the r <= n and r <= p parts fixed it