Last active
November 25, 2025 06:40
-
-
Save ggonnella/b99d9e786476a55f8a04b11f31972505 to your computer and use it in GitHub Desktop.
Dog class for the Python beginners' course
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import sys | |
| class Dog(): | |
| def __init__(self, name, barks=True, bites=True): | |
| self.name = name | |
| self.barks = barks | |
| self.bites = bites | |
| def bite(self, victim): | |
| if self.bites: | |
| print(f"The dog \"{self.name}\" bites {victim}, and {victim} goes to Pasteur to get a rabies vaccination.") | |
| else: | |
| sys.stderr.write(f"Error: dog \"{self.name}\" does not bite!") | |
| def bark(self): | |
| if self.barks: | |
| print(f"{self.name} says 'Wof, wof!'") | |
| else: | |
| sys.stderr.write(f"Error: dog {self.name} does not know how to bark!") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment