This is because strings are immutable in Python.
Which means that X.replace("hello","goodbye")
returns a copy of X
with replacements made. Because of that you need replace this line:
X.replace("hello","goodbye")
with this line:
X = X.replace("hello","goodbye")