Javairia's Chapter 8 Exercises

by Javairia Warrich

08 Feb 2016

Exercise 1: Write a function called chop that takes a list and modifies it, removing the first and last elements, and returns None. call it several times to check your work.

Exercise 2: Figure out which line of the program is still not properly guarded. See if you can construct a text file which causes the program to fail and then modify the program so that the line is properly guarded and test it to make sure it handles your new text file

Exercise 3: Rewrite the guardian code in the above example without two if statements. Instead, use a compound logical expression using the and logical operator with a single if statement.

Reflection: Exercise 2 and 3 gave me some trouble. I wasn’t sure what the question was asking. For exercise 3, could we use “or” to do the same thing as the and operator?

Javairia is a Junior majoring in Information Science at UNC Chapel Hill. Her hobbies include watching sports (Go Panthers!) and reading. Find Javairia Warrich on Twitter, Github, and on the web.