第九章
程序员文章站
2022-05-30 17:44:24
...
9-1
class Restaurant():
def __init__(self, name, type_,number_served = 0 ):
self.restaurant_name = name
self.cuisine_type = type_
self.number_served = number_served
def describe_restaurant(self):
print(self.restaurant_name)
print(self.cuisine_type)
def open_restaurant(self):
print('The restaurant is open.')
restaurant = Restaurant('KFC', 'Fast Food')
print(restaurant.restaurant_name)
print(restaurant.cuisine_type)
restaurant.describe_restaurant()
restaurant.open_restaurant()
9-2
AAA = Restaurant('AAA', 'Chinese Food')
BBB = Restaurant('BBB', 'Western Fodd')
CCC = Restaurant('CCC', 'Dessert')
9-4
class Restaurant():
def __init__(self, name, type_,number_served = 0 ):
self.restaurant_name = name
self.cuisine_type = type_
self.number_served = number_served
def describe_restaurant(self):
print(self.restaurant_name)
print(self.cuisine_type)
def open_restaurant(self):
print('The restaurant is open.')
def set_number_served(self, number):
self.number_served = number
def increment_number_served(self, number):
self.number_served += number
print(str(restaurant.number_served) + ' persons had meals in this restaurant.')
restaurant.number_served = 15
print(str(restaurant.number_served) + ' persons had meals in this restaurant.')
restaurant.set_number_served(20)
print(restaurant.number_served)
restaurant.increment_number_served(50)
print(restaurant.number_served)
9-6
class IceCreamStand(Restaurant):
def __init__(self, name, type_, flavours, number_served = 0):
super().__init__(name, type_,number_served = 0)
self.flavours = flavours
def display_flavours(self):
for flavour in self.flavours:
print(flavour)
ice = IceCreamStand('ice', 'ice-cream', flavours = ['strawberry', 'melon', 'apple'])
ice.display_flavours()
9-10
from restaurant import Restaurant
MHK = Restaurant('MHK', 'Japanese Food', 100)
MHK.describe_restaurant()
上一篇: webpack loader 使用
下一篇: webpack4打包一个项目的基本步骤
推荐阅读
-
实战SpringCloud响应式微服务系列教程(第九章)使用Spring WebFlux构建响应式RESTful服务
-
【.NET Core项目实战-统一认证平台】第九章 授权篇-使用Dapper持久化IdentityServer4
-
《Spring揭秘》第九章——Spring AOP一世
-
C++primer第九章习题解答
-
荐 JavaSe 基础 - 第九章 对象的创建和使用
-
Vue.js-09:第九章 - 组件基础再探(data、props)
-
ES6看完必会第九章------ 对象的扩展 (可私信解惑,不会来捶我)
-
第九章 动态规划-1261:【例9.5】城市交通路网
-
Up and Running with TensorFlow(第九章)
-
(第九章) Hive企业级调优之本地模式