One thing seems clear: Even if you run it as is, you get error messages in Try it online: "Type error: character_code' expected, found -1' (an integer)". So, it seems to have problems with this input in the first place. I recommend you also try it on the terminal for comparison.