Exercise 1
In this exercise, you had to create a function called ‘chop’ that deleted the first and last elements of a list and returned ‘None’. If you specify ‘return t’ in your function, it prints the middle section of the list that was not deleted. However, when you take this out, the function still works, but it print ‘None’. I’m still not entirely sure what ‘None’ means in this context, though.
Exercise 2
This was an exercise in debugging and guarding. This was a little difficult for me, because it seemed like there were many potential lines of code that could cause it to fail, depending on the text file. However, I decided that the most problematic one was ‘print(words[2])’, because there is nothing checking whether the word in the 2th position was a day of the week. I made the code fail by adding ‘From’ to the beginning of line 61 in the text file. This made the program return ‘automatic’ among the list of days. I solved this by creating a list ‘days’ with all the possible days of the week, and adding another ‘if’ statement using ‘not in’, which I learned from the chapter in Automate the Boring Stuff.
Exercise 3
For this exercise, I essentially combined all my ‘if’ statements into one ‘if’ statement, using ‘and’. I also made all of them ‘negative’ - ‘==’ became ‘!=’ and ‘not in’ became ‘in’. If all of these statements were true, it would print the word in the 2th position.