Advertisement
here2share

# b_switchcase.py

Dec 29th, 2024 (edited)
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.28 KB | None | 0 0
  1. # b_switchcase.py
  2.  
  3. def animal_sound(animal):
  4.     sounds = {
  5.         "cat": "Meow",
  6.         "dog": "Woof",
  7.         "cow": "Moo"
  8.     }
  9.     return sounds.get(animal, "*** Unlisted ***")
  10.  
  11. # Test the function
  12. for animal in 'cat dog cow sloth'.split():
  13.     print(animal_sound(animal))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement