家庭作业帮助 - 面向对象编程
Homework Help - Object-Oriented Programming
在我的介绍 class 中,我们刚刚开始了面向对象编程的部分。这个class是我第一次接触编程,实在是看不懂
我们有一个任务,我们必须创建一个动物 class、一个动物园 class,然后一个动物园管理员程序 运行 来自前两个 [=17] 的信息=]是的。我已经根据我书中的示例输入了程序,但我仍然没有正确地完成它。
如果您能查看我的代码并给我一些反馈或帮助,将不胜感激!
class Animal:
def __innit__(self, animal_type, name):
self.animal_type = animal_type
self.name = name
def get_animal_type(self, animal_type):
self.__animal_type = animal_type
def get_name(self, name):
self.__name = name
def check_mood(self, mood):
input random.txt
print random.random()
Class Zoo:
def __innit__(self):
self.__animals = animal_list
def add_animals(self, animal):
self.__animals.append(animal)
def show_animals(animal_list):
return animal_list
input Animal.py
input Zoo.py
def main():
ADD_ANIMAL = 1
SHOW_ANIMALS = 2
EXIT = 3
def get_manu_choice():
print()
print("Zoo Options")
print("-----------")
print("1. Add Animal")
print("2. Show Animals")
print("3. Exit")
print()
choice = int(input("What would you like to do? "))
while choice < ADD_ANIMAL or choice > EXIT:
choice = int(input("Please choose a valid option: "))
return choice
main()
- innit 应该是 init
在我看来你缺少了一大块功能。您需要一个动物园实例,然后响应输入,向动物园添加另一只动物或打印动物列表。
在我的介绍 class 中,我们刚刚开始了面向对象编程的部分。这个class是我第一次接触编程,实在是看不懂
我们有一个任务,我们必须创建一个动物 class、一个动物园 class,然后一个动物园管理员程序 运行 来自前两个 [=17] 的信息=]是的。我已经根据我书中的示例输入了程序,但我仍然没有正确地完成它。
如果您能查看我的代码并给我一些反馈或帮助,将不胜感激!
class Animal:
def __innit__(self, animal_type, name):
self.animal_type = animal_type
self.name = name
def get_animal_type(self, animal_type):
self.__animal_type = animal_type
def get_name(self, name):
self.__name = name
def check_mood(self, mood):
input random.txt
print random.random()
Class Zoo:
def __innit__(self):
self.__animals = animal_list
def add_animals(self, animal):
self.__animals.append(animal)
def show_animals(animal_list):
return animal_list
input Animal.py
input Zoo.py
def main():
ADD_ANIMAL = 1
SHOW_ANIMALS = 2
EXIT = 3
def get_manu_choice():
print()
print("Zoo Options")
print("-----------")
print("1. Add Animal")
print("2. Show Animals")
print("3. Exit")
print()
choice = int(input("What would you like to do? "))
while choice < ADD_ANIMAL or choice > EXIT:
choice = int(input("Please choose a valid option: "))
return choice
main()
- innit 应该是 init
在我看来你缺少了一大块功能。您需要一个动物园实例,然后响应输入,向动物园添加另一只动物或打印动物列表。