Python problem, help please?
Featured Replies
Сейчас на странице 0
- Нет пользователей, просматривающих эту страницу
A better way to browse. Learn more.
A full-screen app on your home screen with push notifications, badges and more.
Используя этот сайт, вы соглашаетесь Условия использования.
So, as a starter, this would be just a basic problem that I am not able to solve.
Here is the problem:
# E. not_bad
# 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):
return
I am thinking that it should be solved using len function for finding not and bad, so I used it and then when I put this command - s.replace(a to b,'good')
It's giving me an error for this one and I don't think that this would work 'cuz in the problem it has given that erase the whole part from not to bad.
I've been working on that problem since 1 week! But no luck solving it, so those of you masters out there, please tell me a solution.
Also, if you are wondering how I got this len idea is 'cuz of this problem:
# B. both_ends
# Given a string s, return a string made of the first 2
# and the last 2 chars of the original string,
# so 'spring' yields 'spng'. However, if the string length
# is less than 2, return instead the empty string.
def both_ends(s):
a = len(s)
if a < 2:
print
else:
print s[0] , s[-2]
return
A fast response will really be appreciated
I did put this topic in altergaming, but didn't get any response yet. So posting it here hoping to get a quick response