Here’s the Python function that reads a string from stdin, replaces the last character with “4”, and prints the result:

def solve():
    import sys
    S = sys.stdin.readline().strip()
    # Replace only the last character with '4'
    modified = S[:-1] + '4'
    print(modified)

if __name__ == "__main__":
    solve()

Flower Shop