My function was suposed to receive a large string, go through it, and find the maximum number of times the pattern "AGATC" repeats consecutively. Regardless of what I feed this function, my return is always 1.
def agatc(s):
maxrep = 0
temp = 0
for i in range(len(s) - 4):
if s[i] == "A" and s[i + 1] == "G" and s[i + 2] == "A" and s[i + 3] == "T" and s[i + 4] == "C":
temp += 1
print(i)
i += 3
else:
if temp > maxrep:
maxrep = temp
temp = 0
return maxrep
Also tried initializing the for loop with (0, len(s) - 4, 1), got the same return.
I though the problem might be in adding 3 to the i variable (apparently it wasn't), so I added print(i) to see what was happening. I got the following:
45
1938
2049
2195
2952
2957
2962
2967
2972
2977
2982
2987
2992
2997
3002
3007
3012
3017
3022
3689
4754
sif s[i:i+5] == "AGATC".range(len(s) - 4)torange(len(s) - 5).maxrepbe any bigger than1... Once you found a match, you domaxrep = tempbut then initializetemp = 0. Now it will never hold thattemp > maxrepso you will never changemaxrepwhich is now1... Why do you even needtempand theelseclause? Why not justmaxrep += 1once the condition is true?