Hi,
So my homework is to look at 3 strings. If the string has not before bad I am suppose to replace the everything between not and bad with good.
So the strings are:
This movie is not so bad
This dinner is not that bad!
This tea is not hot!
Should be:
This movie is good
This dinner is good!
This tea is not hot!
Here is my code. I can't figure out how change all three.
So not sure how to check for both of them. If I could do that then everything would work.
So my homework is to look at 3 strings. If the string has not before bad I am suppose to replace the everything between not and bad with good.
So the strings are:
This movie is not so bad
This dinner is not that bad!
This tea is not hot!
Should be:
This movie is good
This dinner is good!
This tea is not hot!
Here is my code. I can't figure out how change all three.
def not_bad(s): t = s.split() a = -1 b = -1 newlist = [] newlist2 = [] if "bad!" in t: for x in t: if x == "not": a = t.index(x) if x == "bad" or "bad!": if x == "bad!": yellow = " good!" else: yellow =" good" b = t.index(x) if a < b: newlist = range (a, b) for z in newlist: newlist2.append(z) newlist2.append(b) newlist2 = list(newlist2) newlist2.reverse() for take in newlist2: del t[take] t2 = ' '.join(t) t2 = t2 + yellow return t2 else: t2 = ' '.join(t) return t2 print (not_bad("This dinner is not that bad!")) print (not_bad("This tea is not hot!")) print (not_bad("This movie is not so bad"))I have played around a lot with trying to fix the first loop but no matter what I do either 2 or 3 is always wrong. Trying things like "bad or "bad!" just matches everything because of the article here: https://python-forum.io/Thread-Multiple-...or-keyword
So not sure how to check for both of them. If I could do that then everything would work.