Coursera homework in Python