finalized code for prob 7.