pythonify code for p1 of hw2