Question: BlockPy: #35.2) Animal Splits Write a function all_cats that consumes a comma-separated string of animals and returns whether all of the animals have cat
BlockPy: #35.2) Animal Splits Write a function all_cats that consumes a comma-separated string of animals and returns whether all of the animals have "cat" in their name. For example, the string "gerbil, catfish, dog, cat" would return False, but just "cat, catfish" would return True. If the function consumes an empty string, then it returns True. Unit test this function. Console: at, catfish'l, computed answer was I'gerbil, catfish, dog, cat']. Feedback: Unused Variable View Trace The function all_cats was given a definition on line 2, but was never used after that. Evaluate Run Blocks Split Text Reset Import datasets Upload History 1 from cisc108 import assert_equal 2 def all cats (animals): if animals == "": animals_list = animals.split(",") all_contains_cats = True 3 4 return True 5 else: 6 7 8 9 10 11 12 for value in animals_list: if 'cat' not in value: all_contains_cats = False return all contains_cats 13 assert_equal( ["gerbil, catfish, dog, cat"], ["cat, catfish"])
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
