Okay i got the answer. i changed the permission to the directory using chmod command
sudo chmod a+w /home/ec2-user/PythonProgram