episode_reward +rewardadd line updating the variable state this keeps the variable state updated for the next iterationas you will expect state to reflect the current state/ataribot/bot_ _q_table py while trueepisode_reward +reward state state if donein the if done blockdelete the print statement which prints the reward for each episode insteadyou'll output the average reward over many episodes the if done block will then look like this/ataribot/bot_ _q_table py if donerewards append(episode_rewardbreak after these modifications your game loop will match the following