204k views
1 vote
Write a function all_cats that consumes a comma-separated string of animals and prints 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. Call this function on a string of animals of your choice and print the result.

User Vuzun
by
5.1k points

1 Answer

1 vote

Answer:

  • Image 1 is for the function defining all_cats():

(All the explanation is given in comments before each statement)

  • Image 2 has the code for testing the function all_cats()
  • Last image has the output of the code.

Write a function all_cats that consumes a comma-separated string of animals and prints-example-1
Write a function all_cats that consumes a comma-separated string of animals and prints-example-2
Write a function all_cats that consumes a comma-separated string of animals and prints-example-3
User Charlweed
by
5.6k points