Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help in substrings
#1
*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
Reply
#2
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.
Reply
#3
I cant find the 'edit post' button
Reply
#4
Click on BBCODE link above, or on j craters link!
Reply
#5
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).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Substrings OmarSinno 4 4,475 Sep-26-2017, 06:31 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020