本文整理汇总了Python中animal.Animal.name方法的典型用法代码示例。如果您正苦于以下问题:Python Animal.name方法的具体用法?Python Animal.name怎么用?Python Animal.name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类animal.Animal
的用法示例。
在下文中一共展示了Animal.name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reproduce
# 需要导入模块: from animal import Animal [as 别名]
# 或者: from animal.Animal import name [as 别名]
def reproduce(self, animal1, animal2):
min_age = 24
cannot_get_pregnant = 6
if animal1.age < min_age or animal2.age < min_age:
return "Cannot reproduce. Animals are too young"
# Must discuss these changes!
if animal1.species == animal2.species and animal1.gender != animal2.gender:
if animal1.gender == "female" and animal1.age - animal1.last_pregnancy >= cannot_get_pregnant:
animal1.last_pregnancy = animal1.age + animal1.gestation_period
elif animal2.gender == "female" and animal2.age - animal2.last_pregnancy >= cannot_get_pregnant:
animal2.last_pregnancy = animal2.age + animal2.gestation_period
baby = Animal(animal1.species, 0, None, self.gender_baby(), animal1.newborn_weight)
while True:
baby.name = self.name_baby(baby)
if self.does_name_exist(baby.name, baby) is False:
break
self.accommodate(baby)
return baby
else:
return "Cannot reproduce"