Inverted Pendulum Simulation in Python