CS 0008: Spring 2015 Lab 7 YOUR NAME: YOUR PARTNER'S NAME: To get credit on this lab, attend recitation, work with your partner to answer the questions, and give "reasonable" (if not all correct) answers. Each of you should hand in a hardcopy of your own solution, due at the beginning of next week's recitation. This lab will give you practice with slicing and dicing strings and lists, accessing elements of nested lists, and comparing mutable versus immutable objects. You will be working with the shell. Please write down (next to the *s) what you think will be printed and then enter the code. If your answer was wrong, please be sure to understand the code before moving to the next question. Remember, number the positions between the string and list elements. That way, the slices will make sense >>> s1 = "I poured Spot remover on my dog." >>> s2 = "Now he's gone." >>> s1[4:9] * >>> s2[-1] * >>> s2[:7] * >>> s1[6:] * >>> s1[:3] + s1[4:] * >>> lst = [1,2,3] >>> help(list.extend) Help on method_descriptor: extend(...) L.extend(iterable) -- extend list by appending elements from the iterable >>> lst.extend([44,55]) >>> lst * >>> lst.extend(range(2,5)) >>> lst * >>> lst.extend("Dog") >>> lst * >>> lst.remove(44) >>> lst.remove(55) >>> lst * >>> lst = [] >>> lst1 = [0,1,2] >>> lst2 = ["Spot","remover"] >>> lst3 = [[3,4],[5,6]] >>> lst.append(lst1) >>> lst * >>> lst.append(lst2) >>> lst * >>> lst.append(lst3) >>> lst * >>> lst[1] * >>> lst[2] * >>> lst[3] * >>> lst[2] * >>> lst[2][0] * >>> lst[2][0][1] * >>> Write code that inputs an int between 1 and 5 from the user, and creates a list called "lst" that contains that many empty lists. For example, if the user enters 3, your code should create [[],[],[]]. * * * * >>> lst * >>> board = [] >>> for i in range(3): ... row = [] ... for col in range(3): ... row.append("*") ... board.append(row) ... >>> board What is printed here? * >>> >>> lst = [2,3,4] >>> lst.remove(3) >>> lst * >>> s = "Death is hereditary" >>> s[0] = "d" * >>> lst[0] = 0 >>> lst * >>> def fun1(s): ... s * 3 ... return None ... >>> s1 = "You're unique like everyone else" >>> fun1(s1) >>> s1 * >>> def fun2(s): ... return s * 3 ... >>> s1 = fun2(s1) >>> s1 * >>> def fun3(lst): ... lst.append("construction") ... >>> x = [3,4,5] >>> fun3(x) >>> x * >>> >>> name = "Darwin" >>> caps = name.upper() >>> caps * >>> name * >>> >>> d = [["knock knock","who's there"],["cash","cash who?"],["No thanks, but I would like a peanut instead","Groan"]] >>> person1 = 0 >>> person2 = 1 >>> for i in d: ... print("P1:",i[person1]) ... print("P2:",i[person2]) ... print() ... * * * * * *