为什么我的DNA模式的DNA模式没有给出正确的输出?

问题描述 投票:1回答:1

如果输入“ATACTCGTCGTCGATCGATACTCGTCTGTCGTCGAGTCGTTCGTCTCGTC”作为dna,并输入“TCGTC”作为模式,则应输出

____ * __ * _____________ * ______ * ___________ * ____ * ____,它在重叠图案的起始位置标记一颗星。

enter image description here

但是我的代码没有给我正确的输出,为什么?

这是我的代码:

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()
python python-3.x
1个回答
3
投票

问题出在这里:dna[i:len(pattern)]:之后的值是结束索引,而不是子字符串的长度。这样做:dna[i:i+len(pattern)]

© www.soinside.com 2019 - 2024. All rights reserved.