if s1 == s2:
return 0
elif len(s1) == len(s2):
mismatch = 0
for i,j in zip(s1,s2):
if i != j:
mismatch +=1
if mismatch == 1:
return 1
elif len(s1) != len(s2):
mismatch = 0
for i,j in zip(s1,s2):
if i != j:
mismatch +=1
if mismatch > 1:
return 2
I am asked to write a code comparing two strings that will be received as parameters for my function. In iterating over them I have to return 0 if they both are the same, 1 if there is a mismatch in one character and 2 if the length of the two characters isn't the same or there is mismatch in more than 1 character.
When I try 'sin' and 'sink' as input strings, my code does not return anything? I have tried to vary my code many different ways but it doesn't help. It also returns nothing if there is a difference of one character like a space in the string and another character.
It seems like a simple enough piece of code and yet I cant seem to write it right. If I try to fix the issue with the space and another character by using .lower() it doesn't take in the 'k' at the end of the string. If I fix that with the .upper() it would not return anything. I fail to see what I'm doing wrong.