Created
November 26, 2014 19:25
-
-
Save gergob/9fcc4fe8c47f1a45d20a to your computer and use it in GitHub Desktop.
Snake class implementation in Python 3.x
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
class Snake(Animal): | |
__temperature = 28 | |
def __init__(self, name, temperature): | |
super().__init__(name, 2, True, 0) | |
self.temperature = temperature | |
# | |
# METHODS | |
# | |
def eat(self, food): | |
if food == "meat": | |
super().eat(food) | |
else: | |
raise ValueError | |
# | |
# PROPERTIES | |
# | |
@property | |
def temperature(self): | |
return self.__temperature | |
@temperature.setter | |
def temperature(self,new_temperature): | |
if new_temperature < 10 or new_temperature > 40: | |
raise ValueError | |
self.__temperature = new_temperature |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment