Re: String2.py Exercise help please

118 views
Skip to first unread message

Andy Withers

unread,
Mar 10, 2021, 8:24:29 AM3/10/21
to python-g...@googlegroups.com
b is the position in the string s of the word "bad". Specifically, it gives you the index position of the start of the word. So when you replace it, you need to replace to the end of the word, which is the start position + 3 (because the word "bad" is 3 letters long). 

Hope that makes sense

On Wed, 10 Mar 2021 at 06:52, Jasper Jones <orionthe...@gmail.com> wrote:
I was able to figure most of this one out but the end has something that i'm confused about. At the end where s = s[:n] + 'good' + s[b+3:] i'm confused what b+3 is?? I get that b references b but +3?? Here's the full code:

def not_bad(s):
  n = s.find('not')
  b = s.find('bad')
  if n != -1 and b != -1 and b > n:
    s = s[:n] + 'good' + s[b+3:]
  return s


--
You received this message because you are subscribed to the Google Groups "Python GCU Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-gcu-for...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python-gcu-forum/da38653c-ff54-4b38-859c-279dd4fdfe09n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages