Python Forum
Help in substrings - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Help in substrings (/thread-5704.html)



Help in substrings - TDH - Oct-17-2017

*IM KINDA NEW TO PYTHON*
Down here are my orders for this one, I am allowed to ask anyone for this, this is not an assignment to post but just something
we were given to understand, and I really dont know why doesnt it work, and I open it via cmd and everytime theres the eror message it just closes right away so I don't have a chance to read it
can anyone help me figure out?


# Given a string, find the first appearance of the
# substring 'not' and 'bad'. If the 'bad' follows
# the 'not', replace the whole 'not'...'bad' substring
# with 'good'.
# Return the resulting string.
# So 'This dinner is not that bad!' yields:
# This dinner is good!
def not_bad(s):
string = raw_input("Enter a string")
bad = 'bad'
notstring = 'not'
badfind = string.find(bad)
notfind = string.find(notstring)
substringend = badfind + bad(length)
substring = string[notfind:(substringend+1):1]
if (badfind > notfind):
string.replace(string, substring, 'good')
return string


RE: Help in substrings - j.crater - Oct-17-2017

Hello, please edit your post, or repost, so the code will be included in Python code tags. See help here.
When pasting, use ctrl+shift+v to keep formatting/indentation.


RE: Help in substrings - TDH - Oct-17-2017

I cant find the 'edit post' button


RE: Help in substrings - Larz60+ - Oct-17-2017

Click on BBCODE link above, or on j craters link!


RE: Help in substrings - nilamo - Oct-17-2017

Quote: and I open it via cmd and everytime theres the eror message it just closes right away so I don't have a chance to read it

Add pause = input() to the end, so it'll stay open until you hit "enter".  That way you can see whatever error(s) there are.

Or, run it from the command line, instead of double-clicking it (which is how I'm guessing you're running it now).