Я делал курс Python в Google: https://developers.google.com/edu/python/stringsPython - замена строки
Ссылка на упражнения: https://developers.google.com/edu/python/google-python-exercises.zip
Упражнение: ./google-python-exercises/basic/strings2.py
на следующий экзамен:
# 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):
+++your code here+++
return
Мой ANSW эр был:
def not_bad(s):
not_position = s.find('not')
bad_position = s.find('bad')
if bad_position > not_position:
s = s.replace(s[not_position:],'good')
return s
Когда я побежал проверки я получил следующее:
not_bad
OK got: 'This movie is good' expected: 'This movie is good'
X got: 'This dinner is good' expected: 'This dinner is good!'
OK got: 'This tea is not hot' expected: 'This tea is not hot'
OK got: "It's bad yet not" expected: "It's bad yet not"
Я считаю, что «Этот обед хорошо» == «Этот обед хорошо», но я не уверен, почему я не получаю статус «ОК», но «Х». Я считаю, что я не сдавал экзамен правильно, но результат все еще правильный. Я новичок в Python, поэтому комментарии по этому поводу будут высоко оценены!
'хороший = хороший'!. обратите внимание на '!' – sam
Приятный момент, я попытаюсь исправить это –