D. Do this online reading: Sections 5.5 through 5.7 of How to Think Like a Computer Scientist: Learning with Python 3 by Peter Wentworth, Jeffrey Elkner, Allen B. Downey, and Chris Meyers, doing the next set of questions while you do so. 1. Consider the following code. n = random.randrange(50) if ...: print('Banana')

What statement should be added in the box so the function prints Banana! only if the value of n is larger than 20?

a.  if n<20: b.  if n>20:~ c.  elif n>20: d.  else n>20: 2. Consider the following code. if [box A]: print('A won') elif [box B]

What statements should be in boxes A, B, and C so that the sequence correctly prints either 'A won', 'B won', or 'Game tied' given scoreA (the score of player A) and scoreB (the score of player B).

M. Box A -> if scoreA > scoreB: M. Box B -> elif scoreB > scoreA: M. Box C -> else: M. -> elif scoreB >= scoreA: M. -> else if scoreB > scoreA: D. For the following questions, consider Versions 1 and 2: version 1: if-else, version 2: if-if 3. Versions 1 and 2 will print the same thing given the same x and y. a. True~ b. False 4. Which of the versions runs faster? a. Version 1~ b. Version 2 c. Neither (they run equally fast) 4. Which of the versions is better? a. Version 1~ b. Version 2 c. Neither (they are equally good) D. Watch The Accumulator Pattern (revisited). 5. What is the value of x after the following code executes? x = 2  x = x + 1  x = x + 2  x = x + 3 ANS. 8 6. What is the value of y after the following code executes? y = 2  y = y * 2  y = y * 3 ANS. 12 D. Consider the following code: x = 1  y = 2  z = x + y  x = x + 2  y = y * 2  z = z + x + y  x = x + 3  y = y * 3  z = z + x + y 6. What is the value of x after the above code executes? ANS. 6 6. What is the value of y after the above code executes? ANS. 12 6. What is the value of z after the above code executes? ANS. 28 7. Choose the correct options to produce a function that returns the sum 2 + 4 + 6 + ... + 2n. (For example, this function should return 2 + 4 + 6 + 8, which is 20, when n is 4.) M. Line 1 -> def add_them(n): M. Line 2 ->  total = 0 M. Line 3 ->  for i in range(n): M. Line 4 ->   total = total + (2 * (i + 1)) M. Line 5 ->  return total M. ->   total = 2 * i M. ->   total = total + 2 M. ->  for i in range(n - 1): M. -> def add_them() M. -> total = n D. Watch First Solve a Concrete Example By Hand. 8. True or False: To solve a problem by writing computer code for it, you must understand the problem that you are solving. a. True ~ b. False 8. True or False: One excellent way to figure out how to code the problem that you are solving is to first solve a concrete example by hand.. a. True ~ b. False 9. In choosing a concrete example to solve by hand, you should (check all that apply): a. Choose numbers that make the calculations easy.~ b. Choose spicy foods. c. Avoid symmetry. ~ d. Avoid anything that may lead to a special case.~ e. Avoid carbonated drinks. 10. As you solve the problem by hand, using the concrete example that you have chosen, you should (check all that apply): a. Listen to music by Beethovan. b. Give names to the relevant items.~ c. Write the relevant code. d. Keep track of how you calculated each item, or at least be able to figure out afterwards how you calculated it.~ e. Twist and shout “Roll over, Beethovan.” D. Online Reading: What is Unit Testing? (reading appears in the top image on the right-hand side of the page) 11. Explain briefly, in your own words: What is unit testing? D. Online Reading: Code the Unit Test First. 12. Which of the following is typically faster? a. Code the unit tests for a function, then code the function itself.~ b. Code the function, then code the unit tests for that function. c. The two approaches are equally fast. 13. Writing the unit tests first helps you better understand the problem for which you are writing code. a. True~ b. False