apply doctest for chapter04.py