D. Online reading: Sections 5.1 through 5.10 of How to Think Like a Computer Scientist: Learning with Python 3 by Peter Wentworth, Jeffrey Elkner, Allen B. Downey, and Chris Meyers. From the Open Book Project. 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. M. Line 1 -> def add_n(n): M. Line 2 ->  total = 0 M. Line 3 ->  for i in range(n+1): M. Line 4 ->   total = total + 2 * i M. Line 5 ->  return total M. ->   total = 2 * i M. ->   total = total + 2 M. ->  for i in range(n): M. -> def add_n() D. Online Reading: UNIT TESTING Fundamentals, and a question on Unit Testing in Stack Overflow. 9. What is unit testing? D. Online Reading: Code the Unit Test First. 10. 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 other two approaches are equally fast. 11. Writing the unit tests first helps you better understand the problem for which you are writing code. a. True~ b. False