4 回答
TA贡献1936条经验 获得超6个赞
class IceCreamStand(Restaurant):
def __init__(self,restaurant_name, cuisine_type):
super().__init__(restaurant_name, cuisine_type)
def describe_flavors(self,*flavors):
print(f'{self.restaurant_name} has the following flavors:')
for self.flavor in flavors:
print(f'-{self.flavor}')
restaurant =IceCreamStand('DQ','ice cream')
restaurant.describe_restaurant()
restaurant.describe_flavors('Chocolate','Mango', 'Raspberry', 'Coffee', 'Vanilla')
TA贡献1847条经验 获得超11个赞
据我所知,您正在做 Python 速成课程第 9 章的练习。这是我作为另一个练习的一部分所做的代码。希望这对你有帮助。
class Restaurant():
"""A simple attempt to model a restaurant."""
def __init__(self, restaurant_name, cusisine_type):
self.name = restaurant_name
self.type = cusisine_type
def describe_restaurant(self):
print("Restaurant name is " + self.name.title() + ".")
# print(self.name.title() + " is a " + self.type + " type restaurant.")
def open_restaurant(self):
print(self.name.title() + " is open!")
class IceCreamStand(Restaurant):
"""Making a class that inherits from Restaurant parent class."""
def __init__(self, restaurant_name, cusisine_type):
super().__init__(restaurant_name, cusisine_type)
self.flavor = 'chocolate'
def display_flavors(self):
print("This icrecream shop has " + self.flavor + " flavor.")
# create an instance of IceCreamStand
falvors = IceCreamStand('baskin robbins', 'icecream')
# print("My restaurant name is: " + falvors.name)
# print("Restaurant is which type: " + falvors.type)
falvors.describe_restaurant()
falvors.open_restaurant()
# Calling this method
falvors.display_flavors()
添加回答
举报