## Welcome to HW2-2 task 2! ## Please refer to the assignment page for directions. # Here is an example with two break points: a = 0 a + 5 #1-ex a = 3 b = [max([-10, a - 4]), a + 4] #2-ex ## The answers for the code above would look like this (though you should put the ## answers right after the breakpoint -- i.e. after line 8 for 1-ex and after line 12 for 2-ex) ## ## 1-ex: Name, Type, Value ## a, int, 5 ## CORRECTION: a is actually 0 since the line a + 5 doesn't actually change a ## ## 2-ex: Name, Type, Value ## a, int, 3 ## b, list(int), [-1, 7] ## ## That's everything to this assignment. Remember that you will recieve full credit for each part ## even if you first guess was wrong as long as you correct yourself. The following code has 7 ## breakpoints where you're expected to list the variables. ## ## Also, no, you do NOT need to list the variables from the example code. ####START OF CODE YOU NEED TO EXAMINE#### ## Some of the commands will be new to you. If you see a command you don't understand, ## make a best guess as to what it means (the comments will help.) names = ['Grace', 'Memory', 'Peter', 'Miranda', 'Anna'] count = 5 #1 (breakpoint) names = names + ['The Ocean Park Panda'] count + 1 #2 ## sorted is a built-in function. ## If you give it a list, it will give you a new list that puts the elements of the old list ## in alphabetically sorted order newNames = sorted(names) #3 ## len is a built-in function that gives you the length of a string or list you input. count = len(newNames[-1]) ## list[-1] gives you the LAST element newString = "Ying Ying " + newNames[-1] #4 newString = "A " + newString[24:30] + "!!!" #5 mNames = [] if names[0][0] == 'M': mNames = mNames + [names[0]] if names[1][0] == 'M': mNames = mNames + [names[1]] if names[2][0] == 'M': mNames = mNames + [names[2]] if names[3][0] == 'M': mNames = mNames + [names[3]] if names[4][0] == 'M': mNames = mNames + [names[4]] if names[5][0] == 'M': mNames = mNames + [names[5]] #6 aEndNames = [] for name in names: if name[-1] == "a": # string[-1] gives you the LAST character aEndNames = aEndNames + [ name ] #7