codes to the questions in the chapter1