Reputation: 97
If I input "ATACTCGTCGTCGATCGATACTCGTCTGTCGTCGAGTCGTTCGTCTCGTC" as the dna, and "TCGTC" as the pattern, it should output
____ * __ * _____________ * ______ * ___________ * ____ * ____ where it marks a star at the start position of the overlapping pattern.
But my code is not giving me the correct output, why?
Here's my code:
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()
Upvotes: 0
Views: 77
Reputation: 16942
The problem is here: dna[i:len(pattern)]
. The value after the :
is the ending index, not the length of the substring. Do this instead: dna[i:i+len(pattern)]
.
Upvotes: 3