Chap3 Python Solution with test