如果输入“ATACTCGTCGTCGATCGATACTCGTCTGTCGTCGAGTCGTTCGTCTCGTC”作为dna,并输入“TCGTC”作为模式,则应输出
____ * __ * _____________ * ______ * ___________ * ____ * ____,它在重叠图案的起始位置标记一颗星。
但是我的代码没有给我正确的输出,为什么?
这是我的代码:
def printMatch(dna,pattern):
for i in range(0,len(dna)):
if dna[i:len(pattern)]!=pattern:
dna+="_"
else:
dna+="*"
print(dna)
def main():
dna=input()
pattern=input()
printMatch(dna,pattern)
main()
问题出在这里:dna[i:len(pattern)]
。 :
之后的值是结束索引,而不是子字符串的长度。这样做:dna[i:i+len(pattern)]
。