第五周作业(周一)

第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, 

你可能感兴趣的:(第五周作业(周一))