我已经写了一小段代码,可以检测两个字符串中同一位置是否有任何匹配的字符。如果有,则分数递增1,如果有2个或更多连续匹配字符,则分数递增3,如果没有匹配字符,则分数递减1。 但问题是,当我尝试运行代码时,它会给我一个错误:字符串索引超出范围。 怎么了?非常感谢你。
def pairwiseScore(seqA, seqB):
count = 0
score = 0
while count < len(seqA):
if seqA[count] == seqB[count]:
score = score + 1
count = count + 1
while seqA[count] == seqB[count]: # This is the line the error occurs
score = score + 3
count = count + 1
elif seqA[count] != seqB[count]:
score = score - 1
count = count + 1
return score
目前没有回答
相关问题 更多 >
编程相关推荐