# Name: Solutions # Section: # strings_and_lists.py # ********** Exercise 4.1 ********** def sum_all(number_list): # number_list is a list of numbers total = 0 for num in number_list: total += num return total # Test cases print "sum_all of [4, 3, 6] is:", sum_all([4, 3, 6]) print "sum_all of [1, 2, 3, 4] is:", sum_all([1, 2, 3, 4]) def cumulative_sum(number_list): # number_list is a list of numbers out = [] total = 0 for num in number_list: total += num out.append(total) return out # Test Cases assert cumulative_sum([4, 3, 6]) == [4, 7, 13] assert cumulative_sum([1, 2, 3]) == [1, 3, 6] assert cumulative_sum([2, 4, 6]) == [2, 6, 12] # ********** Exercise 4.2 ********** # Write any helper functions you need here. VOWELS = ['a', 'e', 'i', 'o', 'u'] def pig_latin(word): # word is a string to convert to pig-latin if not isinstance(word, str): return 'Word must be a string' if word[0] in VOWELS: pig_word = word + 'hay' else: pig_word = word[1:] + word[0] + 'ay' return pig_word # Test Cases assert pig_latin("boot") == "ootbay" assert pig_latin("image") == "imagehay" assert pig_latin("hello") == "ellohay" assert pig_latin(66) == "Word must be a string" # ********** HW 2 complete! *********