Machine learning interview question

i understood the question and solution but i wrote the code it is not working can u provide code please