chap 2 code snippet