Exam 3- 2012

Sqrty a f1 b printf4f27 c printf31

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ined. def f1( ): print("Hey") def f2(x): return x ** 2 def f3(x, y): return f2(y) + x def f4(y): import math return math.sqrt(y) (a) f1() (b) print(f4(f2(7))) (c) print(f3(1, 8)) CS 115 Exam 3, Fall 2012 Page 2 of 9 (d) x = 5 print(f2(x), x) (e) y=6 print(f3(y, 1)) CS 115 Exam 3, Fall 2012 Page 3 of 9 Problem 2: 10 points. Consider the following sorted list: L = ['AK', 'AZ', 'CA', 'FL', 'GA', 'MD', 'MN', 'OH', 'PA', 'TX', 'WY'] and the following binary search (which is essentially identical to your lab code): # binary_search() # Finds the position of an item in a list # Parameters: the list; the item to search for # Returns: the item’s position (or None) def binary_search(search_list, value_to_find): first = 0 last = len(search_list) – 1 while first <= last: middle = (first + last) // 2 if value_to_find == search_list[middle]: return middle elif value_to_find < search_list[middle]: last =...
View Full Document

This note was uploaded on 02/08/2014 for the course CS 115 taught by Professor Staff during the Fall '08 term at Sonoma.

Ask a homework question - tutors are online