I got it working for all the tests, but the code is ugly. I think regex or
using string methods would have been easier and neater but like I said we
hadn't covered it in the class yet so didn't think I should use it. I am
embarrassed by how bad the code looks to me.

I am self taught and have written a couple useful scripts but still very
much a beginner and there are definite holes in my knowledge. Hoping this
class fills in some of the holes.

Thanks again all for the suggestions and the tips.

On Wed, Sep 6, 2017 at 8:01 AM, Pat Martin <wpmar...@gmail.com> wrote:

> I knew it was an assignment I just couldn't see it no matter how hard I
> looked at the code. Thanks for the tips on printing the variables, I was
> printing them right after the if statements not at the beginning and ending
> of the loop. I will remember that about True/False and comparisons thanks
> for that as well.
>
> The reason I haven't used regex/methods/etc is it hasn't been covered yet,
> we have only covered basic types, for, while and if statements.
>
> On Wed, Sep 6, 2017 at 1:54 AM, Alan Gauld via Tutor <tutor@python.org>
> wrote:
>
>> 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
>>
>
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to