from rt import run_test, run_test_float, close_enough # ##################### Problem 1 ######################### def describe_string(s): """prec: s is a string postc: returns "LONG" if the string has 10 or more characters and "SHORT" otherwise.""" return "COW" # ##################### Problem 2 ######################### def add_evens(nums): """prec: nums is a list of integers. postc: returns the sum of the EVEN numbers in numss.""" return 0 # ##################### Problem 3 ######################### def opposite_letter(ch): """prec: ch is a one-character string containing a letter. postc: returns the "opposite" letter in the alphabet in lower case: A -> z a -> z B -> y b -> y C -> x c -> x etc.""" return "Q" # ##################### Problem 4 ######################### def zipper_strings(a, b): """prec: a, b are strings. post: returns a string that, starting with a, alternates characters of a and b. When one list is exhausted, the rest of the other is tacked onto the end.""" out = "" return out # ##################### Problem 5 ######################### def maximum_product(lists): """prec: lists is a nonempty list of numerical lists. Note that one of the numerical lists could be empty and that the product of an empty list is 1. postc: returns THE LIST with the largest product. In the event of a tie, it returns the first such list.""" return [] # ##################### Problem 6 ######################### def nuggets(limit, nugget_list): """prec: limit is an nonnegative integer postc: nugget_list is a list of nonnegative integers returns a list from nugget_list that has the highest total without exceeding the limit. """ return [] print("************* Tests for Problem 1 **************") run_test(describe_string, "LONG", ["antidisestablishmentarianism"]) print("************* Tests for Problem 2 **************") run_test(add_evens, 30, [[1,4,7,9,10,16]]) print("************* Tests for Problem 3 **************") run_test(opposite_letter, "z", ["a"]) print("************* Tests for Problem 4 **************") run_test(zipper_strings, "cdaotggie", ["cat", "doggie"]) print("************* Tests for Problem 5 **************") run_test(maximum_product, [6,6,6], [[[1,2], [5,6,7], [3, 0], [6,6,6]]]) print("************* Tests for Problem 6 **************") run_test(nuggets, [4, 16], [20, [1, 2, 4, 8, 16]])