第五周作业(周一)

第9章作业

习题9-1

class Restaurant():
    def __init__(self, restaurant_name, cuisine_type):
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type

    def describe_restaurant(self):
        print("This is " + self.restaurant_name + ". \nIt's type is " + self.cuisine_type)

    def open_restaurant(self):
        print(self.restaurant_name + " is open")

restaurant = Restaurant("JinPeng", "Fast Food")
print(restaurant.restaurant_name)
print(restaurant.cuisine_type)
restaurant.describe_restaurant()
restaurant.open_restaurant()
JinPeng
Fast Food
This is JinPeng. 
It's type is Fast Food
JinPeng is open

习题9-2

class Restaurant():
    def __init__(self, restaurant_name, cuisine_type):
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type

    def describe_restaurant(self):
        print("This is " + self.restaurant_name + ". \nIt's type is " + self.cuisine_type)

    def open_restaurant(self):
        print(self.restaurant_name + " is open")

a = Restaurant("JinPeng", "Fast Food")
a.describe_restaurant()
b = Restaurant("Kaiqi", "Junk Food")
b.describe_restaurant()
c = Restaurant("Zihui", "Sea Food")
c.describe_restaurant()
This is JinPeng. 
It's type is Fast Food
This is Kaiqi. 
It's type is Junk Food
This is Zihui. 
It's type is Sea Food

习题9-4

class Restaurant():
    def __init__(self, restaurant_name, cuisine_type):
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type
        self.number_served = 0

    def describe_restaurant(self):
        print("This is " + self.restaurant_name + ". \nIt's type is " + self.cuisine_type)

    def open_restaurant(self):
        print(self.restaurant_name + " is open")

    def set_number_served(self, number):
        self.number_served = number
        print("Total Number Served: " + str(number))

    def increment_number_served(self):
        self.number_served = self.number_served + 1
        print("Total Number Served: " + str(self.number_served))

a = Restaurant("Jinpeng", "Fast Food")
a.set_number_served(10)
a.increment_number_served()
Total Number Served: 10
Total Number Served: 11

习题9-6

class Restaurant():
    def __init__(self, restaurant_name, cuisine_type):
        self.restaurant_name = restaurant_name
        self.cuisine_type = cuisine_type

    def describe_restaurant(self):
        print("This is " + self.restaurant_name + ". \nIt's type is " + self.cuisine_type)

    def open_restaurant(self):
        print(self.restaurant_name + " is open")

class IceCreamStand(Restaurant):
    def __init__(self, restaurant_name, cuisine_type, flavors):
        super().__init__(restaurant_name, cuisine_type)
        self.flavors = flavors

    def print_flavors(self):
        print("Our flavors: ", end="")
        for i in self.flavors:
            print(i + ", ", end="")
        print("")

a = IceCreamStand("QuWeishan", "Ice", ['caomei', 'qiaokeli'])
a.describe_restaurant()
a.print_flavors()
This is QuWeishan. 
It's type is Ice
Our flavors: caomei, qiaokeli, 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值