1. def ln(a): a[1]=4 return a b =[3, 15, 17] c = [4, 24] print (c) c = ln(b) print (c) 2. What is printed by the following statements? alist = [4, 2, 8, 6, 5] blist = [ ] for item in alist: blist.append(item+5) print(blist) (A) [4, 2, 8, 6, 5] (B) [4, 2, 8, 6, 5, 5] (C) [9, 7, 13, 11, 10] (D) Error, you cannot concatenate inside an append. 3. What does the following output ERROR if line would cause error a = (5,6) def abc(a): a[1] = 2 return a x = abc(a) print(x) 4. What does the following print? a = "Hello World" print(a[0:5]) 5. What is the main difference between a list and a tuple? 6. Link is wondering what food will be cooked with this code , but he doesn't know how to read code. Help him out by tell him what will print. inventory = {'monster extract': 105, 'cane sugar': 7, 'goat butter': 10, 'tabantha wheat': 30} for akey in inventory.keys(): print("Use ", inventory[akey], akey) ks = list(inventory.keys()) print(ks, " = Monster cake") 7. Use string methods on the variable thanks to make the new string "thank you!": thanks = "ThAnK YoU!" 8. Consider the following code: import random def rannum(): A=random.randint(2,6) return A What values can it return? A) 2,3,4,5,or 6 B) 3,4,5,6 C) 2,3,4, or 5 D) 3,4,5 9. What is printed by the following code? a = 5*2 b = 4/2 c = 3 print(int((b ** c + a // 2 + (a / b) * 3 // 10))) 10. What's the output of the following code? dict1 = { "Model" : "Toyota", "Year" : "2015" } dict2 = { "Model" : "Honda", "Year" : "2018", } alist = [dict1, dict2] for i in alist: i [ "color"] = "red" print (alist) 11. Convert the decimal number 28 to binary (with no leading zeros). 12. Convert the binary number 1101011 to decimal. 13. What does this code below print? dictionary = {"A": 10, "B": 15, "C": 5} dictionary["A"] += 4 dictionary["C"] -= 5 dictionary["D"] = 2 dictionary["E"] = 3 print(dictionary["C"] + dictionary["D"]) 14. What will the following program print? nudibranchs = ['Sea lemon', 'hooded', 'Opalescent', 'shaggy mouse'] count = 0 for species1 in nudibranchs[0:3]: for species2 in nudibranchs[nudibranchs.index(species1) + 1:]: if species1 < species2: count += 1 print(count) 15. You are given a list, USStates, of 50 dictionaries, with each dictionary containing the "name" of the state, "population", "area", and their state "flower" as keys with their corresponding value. Write code that checks to see if the list contains a dictionary whose "name" field equals "Alabama". If the variable exists within the list or dictionaries, print "state found" once If not, print "state not found" once. 16. Which of the following commands opens a file to read: (a) open(filename, "w") (b) open(filename, "read") (c) open(filename, "r") (d) open(filename, "open") 17. What does the following print? print([1, 2, 3, 4, 5][2:-1]) 18. What does the following code output? def x(y): y[0] = 10 return y a = [4, 7] b = x(a) c = [4, 8] print(a[0], b[0], c[-1]) 19. What will the following code print? for i in range(0,6): if i == 2: print("Two") else: print("Not Two") 20. Given the following list, which of the expressions evaluate to True? Select all that apply. rand_ list = ["Goblins", 7, 8, 9, "504"] 1) 504 in rand_list 2) "Goblins" in rand_list 3) 7 and 8 not in rand_list 4) rand_list[2] == 8 5) rand_list[1:] == [7, 8, 9, "504"] 21. Which of the following are mutable? strings lists dictionaries tuples 22. What will the output of the following code be? list_a = [5, 9, 12] list_b = list_a[:] list_a[1] = 13 var = list_b[1] list_b = list_a print(var, list_b, sep=": ") A) 13: [5, 13, 12] B) 9 [5, 13, 12] C) 9: [5, 13, 12] D) 9, 5, 13, 12 E) none of the above 23. What is the output of the following program? animals = ["bird", "snake", "giraffe"] animals.extend(["lion", "goat", "monkey"]) d = {} for a in animals: if a > animals[3]: d[a] = 0 print(d) 24. What does a.upper() evaluate to if a == "lower"? 25. Question: What is the output? a={} a["key"]="b" b=[] b.insert(0,a) for c in b: a["key"]= "c" print(b) 26. What does this code print? a =[1,6,3] b = a b[2]= 4 print(a[1:]) 27. a = (1, 2) b = (3, 4) c = [a, b] d = [a[::-1], b[::-1]] e = {1:d, 2:c} What is the output of print(e)? 28. What does the following code print? def cube(x): y = x * x * x return y cube_it = 5 after_cube = cube(cube_it) print(cube_it, "cubed equals", after_cube) 29. What does the following print? [Editor's note: in lexicographic ordering, all digits come before all upper and lower case letters]. a="5has6FriendsAnd7Enemies" for i in range(len(a)): if a[i] > a[1]: print(a[i],end="")