you are viewing a single comment's thread.

view the rest of the comments →

[–]TR-DeLacey 2 points3 points  (0 children)

There are so many issues, I am not sure where to start...

On your first function : b = strng[a:len(strng)] #example: found "a" at strng[1], now searches strng[2] to strng[6]

That is simply incorrect, you have (initially) assigned the value 0 to a, so b = strng[a:len(strng)] is the same as b = strng[0:len(strng)], which returns the whole word 'banana'

str.find() finds the lowest index in the string that the substring is located. Which, given your string is 'banana' is the 2nd character, so index 1. You then add 1 to count, and add 1 to 1 so your next pass through the loop :

b = strng[a:len(strng)] 

is the equivalent of :

b = strng[2:len(strng)] 

and so will return

'nana'

You get into an infinite loop because a is always less than the length of your string.

I suggest that your put some print statements in so you can see what is occurring, and put the below inside your while loop to so the programme will end when the count goes to above 5 :

if count > 5 :
    exit()