I’m trying to create a program that can analyze a string sequence. Currently, my program is capable of examining the sequence character by character, but I don’t know how to cleanly get it to recognize the end of the string, which will be variable.
str_exp="ABCDAABKLYWAKAT"
n=0
x=5
while n<=10:
window=str_exp[n:x]
print window,
n+=1
x+=1
countA=window.count('A')
print countA
This should output:
ABCDA 2
BCDAA 2
CDAAB 2
DAABK 2
AABKL 2
ABKLY 1
BKLYW 0
KLYWA 1
LYWAK 1
YWAKA 2
WAKAT 2
You just need to change the condition on your
whileloop to be based onlen(str_exp), which will detect the length of the string. I’ll leave it up to you to figure out the arithmetic, because you’ve got all the basic pieces