CIT 590 Makeup Quiz, Spring 2010 Name ______________________________

Tell what each method below does (not how it does it). That is, tell what the result of the function is. If the function does anything in addition to returning a result, also say what that is. 4 points each.

 def f1(ints): # ints is a list of integers result = 0 for i in range(0, len(ints)): if ints[i] < result and ints[i] > 0: result = ints[i] return result Returns zero. def f2(ints): # ints is a list of integers result = 100 for i in range(0, len(ints)): if ints[i] < result and ints[i] > 0: result = ints[i] return result Returns the smallest positive integer in the list less than 100 (or 100, if no such numbers in the list). def f3(ints): # ints is a list of integers result = ints for i in range(1, len(result)): result[i] += result[i - 1] return result 2 points for saying the function returns a list containing the cumulative sums. (No points for saying each location has the previous location added to it.) 2 more points for noticing that the original array is modified. def f4(ints): # ints is a list of integers count = 0 for i in range(0, len(ints)): if ints[i] > 100: count += 1 else: return count 3 points for saying that it counts how many numbers precede the first number <= 100. 1 more point for noticing that it returns None if all the numbers are greater than 100. def f5(lst): # lst is a list last = len(lst) - 1 for i in range(0, len(lst)): temp = lst[i] lst[i] = lst[last - i] lst[last - i] = temp return lst Returns the list unchanged.