class Pet:
def __init__(self, name, animal_type, age):
self.__name = name
self.__animal_type = animal_type
self.__age = age
def set_name(self, name):
self.__name = name
def set_animal_type(self, animal_type):
self.__animal_type = animal_type
def set_age(self, age):
self.__age = age
def get_name(self):
return self.__name
def get_animal_type(self):
return self.__animal_type
def get_age(self):
return self.__age
def display_details(self):
return "Pet {} is a {}, and it is {} years old".format(self.__name, self.__animal_type,
self.__age)
//问题就在这里^
name = input("Enter pet name:")
animal_type = input("Enter pet type:")
age = int(input("Enter age of pet:"))
Pet(name, animal_type, age)
//我试图在display_details下显示句子,但在输出中看不到它 //llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll
您是否创建了宠物类的实例?即:
相关问题 更多 >
编程相关推荐