D. Do the online reading: <a href="http://www.rose-hulman.edu/class/csse/csse120/VideoFiles/11.1-OverloadingThePlusSymbol/Handouts/OverloadingThePlusSymbol.pdf" target=newtab><b>Overloading the plus operator</b></a>, doing the next set of questions while you do so. 1. <code>11 + 22</code> evaluates to: (NOTE: write <code>error</code> if evaluating the expression generates an error.) ANS. 33 2. <code>'11' + '22'</code> evaluates to: (NOTE: write <code>error</code> if evaluating the expression generates an error.) ANS. '1122' ANS. 1122 ANS. "1122" 3. <code>'11' + str(3 + 3) + '22'</code> evaluates to: (NOTE: write <code>error</code> if evaluating the expression generates an error.) ANS. '11622' ANS. "11622" ANS. 11622 4. <code>'11' + 33</code> evaluates to: (NOTE: write <code>error</code> if evaluating the expression generates an error.) ANS. error ANS. ERROR 5. What does the following code snippet print: <pre> x = 1 <br> y = 2 <br> z = 3 <br> print(x, y, z)</pre> a. <code>1, 2, 3</code> b. <code>1 2 3</code>~ c. <code>6</code> d. <code>123</code> 6. What does the following code snippet print: <pre> x = 1 <br> y = 2 <br> z = 3 <br> print(str(x) + str(y) + str(z))</pre> a. <code>1, 2, 3</code> b. <code>1 2 3</code> c. <code>6</code> d. <code>123</code>~ 7. What does the following code snippet print: <pre> x = 1 <br> y = 2 <br> z = 3 <br> print(x + y + z)</pre> a. <code>1, 2, 3</code> b. <code>1 2 3</code> c. <code>6</code>~ d. <code>123</code> 8. What does the following code snippet print: <pre> x = 1 <br> y = 2 <br> z = 3 <br> print(str(x + y) + str(z))</pre> ANS. 33 9. Implement a function named <code>print_equation</code> that given two numbers <code>x</code> and <code>y</code>, prints an equation for the sum of them. For example, if <code>x</code> is <code>65</code> and <code>y</code> is <code>11</code>, the function would print <code>65+11=76</code>. M. Line 1 -> def print_equation(x, y): M. Line 2 -> print(str(x) + "+" + str(y) + "=" + str(x+y)) M. -> print(x, y, x+y) M. -> print(x+++y+ = +x+y) M. -> print("65+11=76") D. Do the online reading: <a href="http://www.rose-hulman.edu/class/csse/csse120/VideoFiles/11.2-AccumulatingSequences/Handouts/AccumulatingSequences.pdf" target=newtab><b>Accumulating Sequences</b></a>, doing the next set of questions while you do so. D. On a piece of paper (NOT here in Moodle), implement the following function, per its doc-string. You do NOT have to be completely correct, just try to get the main idea correct, with guidance from the reading. After you have made a reasonable try, turn to the next page in this Moodle quiz for a solution. <pre>def make_simple_list(m, n):<br> """<br> Returns the list [m, m+1, m+2, ... n],<br> where m and n are the given arguments.<br> For example, if m is 5 and n is 13,<br> then this function returns:<br> [5, 6, 7, 8, 9, 10, 11, 12, 13]<br> """</pre> D. Here is a solution to the previous problem. Compare your solution to it. Bring any questions about this problem to class.<pre>def make_simple_list(m, n):<br> """ Same specification as on the previous item. """<br> seq = []<br> for k in range(m, n + 1):<br> seq = seq + [k]<br> return seq<br></pre> 1. Consider the following code. What should the missing statement be (that is, the statement marked ???).<pre>def make_list(n):<br> """<br> Returns the list [1, 2, 3, ... n],<br> where n is the given argument.<br> For example, if n is 5,<br> then this function returns:<br> [1, 2, 3, 4, 5]<br> """<br> seq = []<br> for k in range(n):<br> ???<br> return seq<br></pre> a. <code> seq = seq[k]</code> a. <code> seq = seq[k + 1 ]</code> b. <code> seq = seq + k</code> b. <code> seq = seq + k + 1</code> c. <code> seq = seq[k] + [k]</code> d. <code> seq[k] = seq[k] + [k]</code> e. <code> seq = seq + [k + 1]</code>~ e. <code> seq = seq + seq[k]</code> e. <code> seq = seq + seq[k + 1]</code> 2. What does the following code snippet print: (Note: If your answer includes any commas, put a SINGLE SPACE after each comma, to help out the automated grading. But no problem if you get the right answer except for spaces.) <pre> x = 0 <br> for k in range(5): <br> x = x + (2 * k) <br> print(x) </pre> ANS. 20 2. What does the following code snippet print: (Note: If your answer includes any commas, put a SINGLE SPACE after each comma, to help out the automated grading. But no problem if you get the right answer except for spaces.) <pre> x = [] <br> for k in range(5): <br> x = x + [(2 * k)] <br> print(x) </pre> ANS. [0, 2, 4, 6, 8] 2. What does the following code snippet print: (Hint: ignore the comma in the code, but ask in class why it is necessary.) (Note: If your answer includes any commas, put a SINGLE SPACE after each comma, to help out the automated grading. But no problem if you get the right answer except for spaces.) <pre> x = () <br> for k in range(5): <br> x = x + ((2 * k),) <br> print(x) </pre> ANS. (0, 2, 4, 6, 8) 2. What does the following code snippet print: (Note: If your answer includes any commas, put a SINGLE SPACE after each comma, to help out the automated grading. But no problem if you get the right answer except for spaces.) <pre> x = '' <br> for k in range(5): <br> x = x + str(2 * k) <br> print(x) </pre> ANS. 02468 ANS. '02468' ANS. "02468" D. In the above question, make sure that you understand why applying the built-in <code>str</code> function is necessary. D. Watch the video: <a href="http://www.rose-hulman.edu/class/csse/csse120/VideoFiles/11.3-PatternsForIteratingThroughSequences/Video/PatternsForIteratingThroughSequences/PatternsForIteratingThroughSequences.mp4" target=newtab><b>Sequences</b></a>, doing the next set of questions while you do so. D. For the next set of questions, consider the following three function definitions:<pre>def foo1(seq):<br> total = 0<br> for k in range(len(seq) // 2):<br> total = total + seq[1 + (2 * k)]<br> return total<br><br><br>def foo2(seq):<br> total = 0<br> for k in range(1, len(seq), 2):<br> total = total + seq[k]<br> return total<br><br><br>def foo3(seq):<br> total = 0<br> m = 1<br> for _ in range(len(seq) // 2):<br> total = total + seq[m]<br> m = m + 2<br> return total<br></pre> 1. To what number does <code>foo1([3])</code> evaluate? a. 0~ b. 1 c. 2 d. 3 e. 4 f. 5 g. 6 h. 7 i. 8 j. 9 k. 10 l. 11 m. 12 n. 13 o. 14 p. 15 q. 16 r. 17 r. 18 r. 19 r. 20 r. 24 r. 33 r. 38 1. To what number does <code>foo1([3, 6])</code> evaluate? a. 0 b. 1 c. 2 d. 3 e. 4 f. 5 g. 6~ h. 7 i. 8 j. 9 k. 10 l. 11 m. 12 n. 13 o. 14 p. 15 q. 16 r. 17 r. 18 r. 19 r. 20 r. 24 r. 33 r. 38 1. To what number does <code>foo1([3, 6, 1, 4, 9, 5])</code> evaluate? a. 0 b. 1 c. 2 d. 3 e. 4 f. 5 g. 6 h. 7 i. 8 j. 9 k. 10 l. 11 m. 12 n. 13 o. 14 p. 15~ q. 16 r. 17 r. 18 r. 19 r. 20 r. 24 r. 33 r. 38 1. To what number does <code>foo2([3])</code> evaluate? a. 0~ b. 1 c. 2 d. 3 e. 4 f. 5 g. 6 h. 7 i. 8 j. 9 k. 10 l. 11 m. 12 n. 13 o. 14 p. 15 q. 16 r. 17 r. 18 r. 19 r. 20 r. 24 r. 33 r. 38 1. To what number does <code>foo2([3, 6])</code> evaluate? a. 0 b. 1 c. 2 d. 3 e. 4 f. 5 g. 6~ h. 7 i. 8 j. 9 k. 10 l. 11 m. 12 n. 13 o. 14 p. 15 q. 16 r. 17 r. 18 r. 19 r. 20 r. 24 r. 33 r. 38 1. To what number does <code>foo2([3, 6, 1, 4, 9, 5])</code> evaluate? a. 0 b. 1 c. 2 d. 3 e. 4 f. 5 g. 6 h. 7 i. 8 j. 9 k. 10 l. 11 m. 12 n. 13 o. 14 p. 15~ q. 16 r. 17 r. 18 r. 19 r. 20 r. 24 r. 33 r. 38 1. To what number does <code>foo3([3])</code> evaluate? a. 0~ b. 1 c. 2 d. 3 e. 4 f. 5 g. 6 h. 7 i. 8 j. 9 k. 10 l. 11 m. 12 n. 13 o. 14 p. 15 q. 16 r. 17 r. 18 r. 19 r. 20 r. 24 r. 33 r. 38 1. To what number does <code>foo3([3, 6])</code> evaluate? a. 0 b. 1 c. 2 d. 3 e. 4 f. 5 g. 6~ h. 7 i. 8 j. 9 k. 10 l. 11 m. 12 n. 13 o. 14 p. 15 q. 16 r. 17 r. 18 r. 19 r. 20 r. 24 r. 33 r. 38 1. To what number does <code>foo3([3, 6, 1, 4, 9, 5])</code> evaluate? a. 0 b. 1 c. 2 d. 3 e. 4 f. 5 g. 6 h. 7 i. 8 j. 9 k. 10 l. 11 m. 12 n. 13 o. 14 p. 15~ q. 16 r. 17 r. 18 r. 19 r. 20 r. 24 r. 33 r. 38 D. For the next set of questions, consider the following two attempts at a function that <strong>returns the first negative item in the sequence of numbers, or <code>None</code> if the sequence contains no negative numbers.</strong> One function is correct and the other is wrong. <pre>def find1(numbers):<br> for k in range(len(numbers)):<br> if numbers[k] < 0:<br> return numbers[k]<br> else:<br> return None<br><br><br>def find2(numbers):<br> for k in range(len(numbers)):<br> if numbers[k] < 0:<br> return numbers[k]<br> return None<br></pre> 1. What gets returned by the function call <code>find1( [-3, 6, 1, 4, 9, 5] )</code>? ANS. -3 1. What gets returned by the function call <code>find2( [-3, 6, 1, 4, 9, 5] )</code>? ANS. -3 1. What gets returned by the function call <code>find1( [3, 6, 1, 4, 9, 5] )</code>? ANS. None 1. What gets returned by the function call <code>find2( [3, 6, 1, 4, 9, 5] )</code>? ANS. None 1. What gets returned by the function call <code>find1( [3, -6, 1, 4, 9, 5] )</code>? ANS. None 1. What gets returned by the function call <code>find2( [3, -6, 1, 4, 9, 5] )</code>? ANS. -6 1. Which attempt is correct? a. <code>find1</code> b. <code>find2</code>~ D. IMPORTANT: Be sure that you understand the previous problem and its answer! Bring questions to class!