import gym # Library
env = gym.make('CartPole-v0') # Environment
for i_episode in range(20): # Loop
observation = env.reset() # Get observation
for t in range(100):
env.render()
action = env.action_space.sample() # Select an action
observation, reward, done, info = env.step(action) # Do it and get observation, reward
if done: # Is it over
print("Episode finished")
break