Learn to Program: The Fundamentals - Week 6 Exercise Answers
Learn to Program: The Fundamentals - Week 6 Exercise Score of 13.00 out of 13.00 . Open up IDLE and try out all the code as you do the exercise! Question 1 Consider this code: def merge(L): merged = [] for i in range(0, len(L), 3): merged.append(L[i] + L[i + 1] + L[i + 2]) return merged print(merge([1, 2, 3, 4, 5, 6, 7, 8, 9])) What is printed by the code above? Your Answer Score Explanation [123, 456, 789] [1, 4, 7] [6, 15, 24] Correct 1.00 [12, 15, 18] Total 1.00 / 1.00 Question Explanation Trace the code by hand or in the visualizer, or run the code in IDLE. Question 2 Consider this code: def mystery(s): """ (str) -> bool """ matches = 0 for i in range(len(s) // 2): if s[i] == s[len(s) - 1 - i]: # <-- How many times is this line reached? matches = matches + 1 return matches == (len(s) // 2) mystery('civil') Trace the function call...