On 06/09/17 06:34, Pat Martin wrote: > but my script returns 0. Since they want it to find 2 from the bobob in the > string using "bob in s" doesn't work (it only returns 1).
Your code has bugs and Cameron has addressed those along with general advice on how to debug your code in future. However there are other string methods that could save you some work. At the >>> prompt use dir(str) to see a list of all the methods available. Then use help(str.methodName) to find out what each one does. (Or just browse the string documentation on the web site!) In this case you might find some of the following methods useful: str.count str.find str.index str.startswith and of course you can use string slicing to access a substring. Combining slicing with the parameters of find or index should make your task easier. Finally, if you want to carry on with your loop approach you might find that enumerate is useful here since it gives you the index as well as the character. That will allow you to look-ahead to see if the next two characters are 'ob'... That should simplify things. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor