In order to be able to launch a Python script directly from the Simcenter Amesim sketch you can use the submodel SCRCALL01:

This submodel allows you to launch the script from Parameter or Simulation mode.
You will need to setup the the command interpreter AMEPython, which is the Python executable inside the Simcenter Amesim installation, and route the command to the location, where the script is stored. In this case the script is located inside the UserData folder in the
snake.ame model:

To run the script, you need to right click on the component and launch it:

The script attached to this model starts a small game based classical video game
Snake:
The controls of the snakes are programmed to work with the arrows in your keyboard
.

Attached to this knowledge base article, you will find the Simcenter Amesim model with the game.