D. Watch the video: Sequences, doing the next set of questions while you do so. 1. Sequences are powerful because: a. They let you refer to an entire collection, as well as the items in the collection, using a single name.~ b. They let you iterate and facilitate the creation of terminating loops. c. They are larger than integers. d. They make Python a Turing Complete language. 2. Match the statements to the correct value when
sequence = [74, 34, 13, 30, 4004]
M. len(sequence) -> 5 M. sequence[0] -> 74 M. sequence[1] -> 34 M. sequence[4] -> 4004 M. sequence[len(sequence) - 1] -> 4004 M. -> 13 M. -> 30 M. -> 6 M. -> 0 3. Match the statements to the correct value when
sequence = 'Expert texpert!'
M. len(sequence) -> 15 M. sequence[0] -> 'E' M. sequence[1] -> 'x' M. sequence[4] -> 'r' M. sequence[len(sequence) - 1] -> '!' M. -> 16 M. -> 't' M. -> 'e' M. -> 'p' D. Watch the video: The Last Item in a Sequence, doing the next set of questions while you do so. 4. Choose the expression that represents the first item in a sequence named seq: a. seq[0]~ b. seq[1] c. seq d. seq[len(seq)] e. seq[len(seq) - 1] f. 0 g. 1 5. Choose the expression that represents the last item in a sequence named seq: a. seq[len(seq) - 1]~ b. seq[len(seq)] c. seq[1] d. seq(len) e. seq(len - 1) f. len(seq) g. len(seq) - 1 6. Given that seq is a sequence, what is the result of the expression
seq[len(seq)]
a. An IndexError is generated.~ b. The result is the last item of the sequence. c. The result is the length of the sequence. d. A syntax error is generated. 7. A fellow student turns to you and says "I don't understand why my code is giving me an error on this line:
s[len(s)] = 40
I used len(s) before in my FOR loop and it seemed to work just fine!" The FOR loop to which they referred is:
for k in range(len(s)): 
s[k] = k
What do you tell them to explain why their statement
s[len(s)] = 40
is wrong? a. Previously you used len(s) as an argument to the RANGE function. The last value that the RANGE function yields is the argument - 1 so you accessed the last element in the sequence at index len(s) - 1. The index len(s) is actually one past the end of the sequence!~ b. I don't know, all of your code seems valid. There is probably a problem with Eclipse. c. You probably changed the length of the sequence s sometime between when you used it in your FOR loop and when you later access an element with the code s[len(s)]. d. You can only use a number for the index of a sequence and len(s) is not a number. D. Do the reading on using the RANGE function (see the Session 11 Preparation page). Then watch the video: Iterating Through Sequences, doing the next set of questions while you do so. 8. Write a loop that prints all the elements of sequence x backwards. M. Line 1 -> for k in range(len(x) - 1, -1, -1): M. Line 2 ->      print(x[k]) M. -> for k in range(len(x)): M. -> for k in range(len(x), -1): M. -> for k in range(-1): M. -> for k in range(len(x) - 1, 0, -1): 9. What RANGE statement would you use if you wanted to print all elements of sequence x between indices 4 and 7, inclusive, backwards? Assume that the sequence will have at least 8 elements. a. range(7, 3, -1)~ b. range(8, 3, -1) c. range(6, 3, -1) d. range(7, 4, -1) e. range(8, 4, -1) f. range(6, 4, -1) g. range(7, 5, -1) h. range(8, 5, -1) i. range(6, 5, -1) j. range(3, 7, -1) k. range(3, 8, -1) l. range(3, 6, -1) m. range(4, 7, -1) n. range(4, 8, -1) o. range(4, 6, -1) p. range(5, 7, -1) q. range(5, 8, -1) r. range(5, 6, -1) 10. What RANGE statement would you use if you wanted to print every third element of sequence x, starting at index 1, fowards? Assume that the sequence will have at least 2 elements. a. range(1, len(x), 3)~ b. range(0, len(x), 3) c. range(2, len(x), 3) d. range(1, len(x) - 1, 3) e. range(0, len(x) - 1, 3) f. range(2, len(x) - 1, 3) g. range(1, len(x) - 3, 3) h. range(0, len(x) - 3, 3) i. range(2, len(x) - 3, 3) 11. Which of the following statements constructs a list containing three numbers and assigns the variable numbers to that list. a. numbers = [11, 7, 13]~ b. numbers = (11, 7, 13) c. numbers = '[11, 7, 13]' d. numbers = ['11', '7', '13'] e. numbers = '11, 7, 13' 12. Which of the following statements changes the beginning element (that is, the 11) in the list numbers from the previous problem to 66. a. numbers[0] = 66~ b. numbers[len(numbers)] = 66 c. numbers[1] = 66 d. numbers[11] = 66 e. numbers = 66 f. numbers(0) = 66 g. numbers(11)= 66 13.Which of the following statements changes the last element (that is, the 13) in the list numbers from the previous problem to 4. a. numbers[2] = 4~ b. numbers[3] = 4 c. numbers[4] = 4 d. numbers[len(numbers)] = 4 e. numbers[] = 4 f. numbers[4] = 2 g. numbers[4] = 3 h. numbers[13] = 4 i. numbers[4] = 13 14. Implement a function named sum_all for which: M. Line 1 -> def sum_all(seq): M. Line 2 ->     total = 0 M. Line 3 ->     for k in range(len(seq)): M. Line 4 ->          total = total + seq[k] M. Line 5 ->     return total M. ->     for k in range(seq): M. ->     for k in range(len(seq) - 1): M. -> def sum_all(): M. ->          if k < 0: M. ->          seq[k] = seq[k] + 1 M. ->          total = total + 1 15. Implement a function named count_positives for which: M. Line 1 -> def count_positives(seq): M. Line 2 ->     count = 0 M. Line 3 ->     for k in range(len(seq)): M. Line 4 ->         if seq[k] > 0: M. Line 5 ->             count = count + 1 M. Line 6 ->     return count M. ->     for k in range(seq): M. -> def count_positive(): M. ->         if k < 0: M. ->         if k > 0: M. -> else: M. ->         if seq[k] >= 0: M. ->         if seq[k] < 0: D. Do the reading: Computing & Society 6.1 Computer Viruses, doing the next set of questions while you do so. 16. In November 1988, Robert Morris launched a computer virus (actually, a form of virus called a worm) that, through an error in his code, delivered a denial-of-service attack to computers on the Internet. His worm worked by attacking a program called finger that was written in the programming language C. If finger had been written and run in Python, his attack would NOT have succeeded. a. True~ b. False 17. Very briefly, explain your answer to the previous problem. 18. Morris was convicted under The Computer Fraud and Abuse Act. After appeal, what was his sentence? M. Years probation -> 3 years M. Hours of community service -> 400 hours M. Fine -> $10,000 M. -> $1,000 M. -> 5 years M. -> 1 year, suspended M. -> 100 hours M. -> 1,000 hours M. -> $400 M. -> $50,000 19. In your own opinion, do you feel that his sentence was: [you get full credit for ANY answer here, even though Moodle will probably mark your answer as "wrong"; just select what best fits YOUR opinion] a. A lot too leniant (i.e., he should have gotten a heavier sentence -- jail time, or a longer probation, or more required community service, or a larger fine, or some combination of those) b. A little too leniant c. About right d. A little too severe e. A lot too severe (i.e., he should have gotten a lighter sentence -- a shorter probation, or less required community service, or a smaller fine, or some combination of those) 20. Very briefly, explain your answer to the previous problem.