You can tell print()
not to write a newline by setting the end
keyword argument to an empty string:
print(line.replace("math", "science"), end='')
The default value for end
is '\n'
.
Alternatively you could remove the newline from line
:
print(line.rstrip('\n').replace("math", "science"))