Chapter 9 exercises from Learn to Program