# assumes list has been sorted before call def seq_search_mod(list, target): ans = -1 i = 0 for cur in list: #num_ops = num_ops + 1 if cur < target: # could be later i = i + 1 elif cur > target: # not there break else: # found it ans = i break return ans def main(): while True: list = raw_input("Enter a list (or q to quit): ") if list == 'q': break list = eval(list) list.sort() print "sorted list is: ", list while True: key = raw_input(" Search key (or q to get next list): ") if key == 'q': break key = eval(key) print " result is: ", seq_search_mod(list, key) #print " num comparisons is: ", num_ops print 'Program quits.' main()