1 回答

TA贡献1833条经验 获得超4个赞
这实际上是一个缩进问题。for 循环在 else 缩进中。将 for 循环放在 else 语句的同一级别,解决了它:
def string_match(a, b):
result = 0
tiniest = b
biggest = a
if len(a) < 2 or len(b) < 2:
return 0
if len(a) < len(b):
tiniest = a
print('tiniest is {} and size minus 1 equals {}'.format(str(tiniest), len(tiniest)-1))
biggest = b
else:
tiniest = b
print('ELSE tiniest is {} and size minus 1 equals {}'.format(str(tiniest), len(tiniest) - 1))
biggest = a
for i in range(len(tiniest) - 1):
print(i)
if tiniest[i:i+2] == biggest[i:i+2]:
print('tiniest is {} and biggest is {} and i is {}'.format(tiniest[i:i+2], biggest[i:i+2], i))
result = result + 1
else:
continue
print("result is ",result)
return result
添加回答
举报