Your example is designed to run in a console. It does not fit the BGE in any form.
You need to understand that a Python controller is part of the BGE's game loop. Therefore you should never ever hold the processing in your Python code. You have to exit as fast as possible. Otherwise the game loop will not continue (Remember you have only 16ms for process everything incl. render, logic and physics).
The usual way to enter text within the BGE is to use a keyboard sensor. Typical it reacts on a single keystroke. But you can switch it into log mode to log subsequent keystrokes into a string property.
When the log toggle property (here: enabled) is evaluated as True the sensor converts keypresses into characters and adds them to the target property (here: Text).
- The BGE does not support Keyboard mapping. Therefore the converted key-codes match EN-Keyboards only. (Which means strings entered by other keyboards are incorrect, especially at the special character keys and the Z/Y keys).
- The target property can be any property (it does not need to be "Text")
- The sensor will not trigger connected controllers on key press unless you enable Key or All Keys.
- You need to determine when an input is completed. You can do that either by sensing when the target property changed (property sensor) or when a key was pressed (All Keys enabled).
- The Keyboard sensor only adds characters. You need separate logic to clear the target property (e.g. after completing the input)
To present the entered text to the user I suggest to use a Text object. Copy the target property value from the keyboard sensor to the text attribute (or Text property) of the text object and it will be displayed.
The above example logs directly to the Text property.
I hope it helps