Replace this:
newcontents = contents.replace('a','e')
newcontents = contents.replace('s', '3')
with this:
newcontents = contents.replace('a','e')
newcontents = newcontents.replace('s', '3')
Or better yet:
newcontents = contents.replace('a','e').replace('s', '3')
It seems your code is trying to replace 'a' with 'e', not 'e' with 'a'. To do this, you need the following:
import string
newcontents = contents.translate(string.maketrans("aes", "ea3"))
source
share