On 06Sep2017 09:12, Pat Martin wrote:
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
Always go for string methods first. Regexps are cryptic and easy to get wrong,
and relatively hard to debu
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 writt
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
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
May I suggest you use regular expressions?
You can check it out here (take note of the difference between search,
findall etc):
https://docs.python.org/3/library/re.html
Essentially it is a standard library built for matching patterns in
strings. It is a powerful tool that is kind of it's own lan
On 05Sep2017 22:34, Pat Martin wrote:
I am trying to write a program for a programming class that finds the
number of a specific string (bob) in a string of characters. I am using one
of the sample strings they give me and it should find 2 instances of bob
but my script returns 0. Since they wan
Pat Martin writes:
> My eyes are crossing looking at the code, can someone give me a hint
> on what I am missing that causes this to not give me the correct
> answer of 2.
It's good to admit that looking at the code has ceased to help :-)
So, try a different approach. Without using the code, ca