1. Draw below what the following program would draw on the screen: from turtle import * def draw_something(x, y, length): pu() goto(x, y) pd() goto(x + length, y) for i in range(10): draw_something(0, i*5, i*5) 2. Write a function called my_startswith that takes two strings as parameters and returns True if the first string starts with the second string. You may NOT use the built-in startswith method. You may assume that the second string is shorter than the first. 3. Rewrite each of the bool expressions below more compactly. For example, rather than writing x and x we could just write x ---------------------------- a. # x contains some bool value True and x b. # x contains some bool value False or x c. (y > 0 and z == 1) or (y > 0 and z == 2) 4. For each of the statements below state whether an error would occur OR state what would be printed out. Make sure to make it clear whether you have printed an int, float or a string. print 2 + 5.5 print 15 / 2 print float(15 / 2) print 2 + '3' print str(2) + '3' 5. Write a function called random_test that takes three parameters: an int called max, an int called threshold and an int called num. The function should generate num random numbers between 0 and max (inclusive) and return the number of these values that were less or equal to the threshold. 6. What would the following function return if we called it with 4 as the parameter: def mystery(x): count = 1 total = 0 while count <= x: total += count * count return total 7. If we had the following program in a file and we "ran" the program using the green arrow in Wing, what would you see displayed? def mystery(a_string): return a_string + a_string def mystery2(a_string): print a_string * 2 mystery("CS30 is good") mystery2("CS30 is great") 8. DNA is made up of four different bases, abbreviated A, C, G and T. A DNA sequence consists of some combination of these letters. Write a function called random_DNA that generates a random DNA sequence. Your function should take a single parameter that is the length of the sequence to generate and return a string. 9. Two of the following three functions do the same thing. Identify the two that are the same: def a(x, y): if (x < 0 and y < 0) or (x > 0 and y > 0): return x * y else: return 0 def b(x, y): if x < 0 and y < 0: return x * y elif x < 0: return 0 else: return x * y def c(x, y): if x < 0 and y < 0: return x * y elif x > 0 and y > 0: return x * y else: return 0 10. Write a Python function stringToIntList that takes a string representing a number and returns a list of ints representing the individual digits. For example: >>> stringToIntList("80345") [8, 0, 3, 4, 5] 11. Draw below what the following program would draw on the screen assuming the screen width and height are 700 (-350 to 350). For clarity, feel free to include lines marking the x and y axes. The circle function draws a circle starting the very bottom of the circle. from turtle import * X_MIN = -300 # the smallest x value on the screen X_MAX = 300 # the largest x value on the screen def draw_pattern(radius): x = X_MIN while x < X_MAX: pu() goto(x, 0) pd() if x < 0: begin_fill() circle(radius) end_fill() else: circle(radius) x += 2*radius draw_pattern(50) 12. Suppose that fruits is initialized as follows: fruits = ["kiwi", "banana", "papaya", "mango", "melon"] What would the following statements print (make sure to be clear what the type of the thing is, i.e. string vs. list): a. print fruits[1] b. print fruits[:1] c. print fruits[-3:-1] d. print fruits[2][4] e. print fruits[1:3] * 2 f. print fruits[1] * 2 13. What would the following function return if called with "computer science" as the argument (i.e. hmm("computer science")): def hmm(phrase): output = "" for i in range(len(phrase)): if not(phrase[i] in output): output = output + phrase[i] return output