chapter 9 exercise: think python