practice following http://www.cis.upenn.edu/~lhuang3/cse399-python/homework.html