建立乙個名為restaurant的類,其方法__init__()設定兩個屬性:restaurant_name和cuisine_type。建立乙個名為describe_restaurant()的方法和乙個名為open_restaurant()的方法,其中前者列印前述兩項資訊,而後者列印一條訊息,指出餐館正在營業。
(1)加乙個名為number_served的屬性,並將其預設值設定為0。根據這個類建立乙個名為restaurant的例項;列印有多少人在這家餐館就餐過,然後修改這個值並再次列印它。
class
restaurant()
:def
__init__
(self, restaurant_name, cuisine_type)
: self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
self.number_served =
0def
describe_restaurant
(self)
:print
("name: "
+self.restaurant_name)
print
("type: "
+self.cuisine_type)
defopen_restaurant
(self)
:print
("the restaurant is open!"
)def
read_number_served
(self)
:print
("the number of people had in this restaurant are: "
+str
(self.number_served)
)my_restaurant = restaurant(
'jinling'
,'chinese'
)my_restaurant.describe_restaurant(
)my_restaurant.open_restaurant(
)my_restaurant.number_served =
23#修改就餐人數
my_restaurant.read_number_served(
)
(2)新增乙個名為set_number_served()的方法,它讓你能夠設定就餐人數。呼叫這個方法並向它傳遞乙個值,然後再次列印這個值。
class
restaurant()
:def
__init__
(self, restaurant_name, cuisine_type)
: self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
self.number_served =
0def
describe_restaurant
(self)
:print
("name: "
+self.restaurant_name)
print
("type: "
+self.cuisine_type)
defopen_restaurant
(self)
:print
("the restaurant is open!"
)def
read_number_served
(self)
:print
("the number of people had in this restaurant are: "
+str
(self.number_served)
)def
set_number_served
(self, number)
:"""將人數設定為指定的值"""
(3)新增乙個名為increment_number_served()的方法,它讓你能夠將就餐人數遞增。呼叫這個方法並向它傳遞乙個這樣的值:你認為這家餐館每天可能接待的就餐人數。
class
restaurant()
:def
__init__
(self, restaurant_name, cuisine_type)
: self.restaurant_name = restaurant_name
self.cuisine_type = cuisine_type
self.number_served =
0def
describe_restaurant
(self)
:print
("name: "
+self.restaurant_name)
print
("type: "
+self.cuisine_type)
defopen_restaurant
(self)
:print
("the restaurant is open!"
)def
read_number_served
(self)
:print
("the number of people had in this restaurant are: "
+str
(self.number_served)
)def
set_number_served
(self, number)
:"""將人數設定為指定的值"""
self.number_served = number
defincrement_number_served
(self, ince)
:"""將人數增加指定增量"""
self.number_served+= ince
my_restaurant = restaurant(
'jinling'
,'chinese'
)my_restaurant.describe_restaurant(
)my_restaurant.open_restaurant(
)my_restaurant.set_number_served(45)
my_restaurant.read_number_served(
)my_restaurant.increment_number_served(10)
my_restaurant.read_number_served(
)
Python作業9 4就餐人數
usr bin env python3 encoding utf 8 please write your outline code.class restaurant 餐館的相關資訊 建構函式 def init self,restaurant name,cuisine type 上一句,其中 rest...
Python入門習題大全 就餐人數
在為完成練習 餐館 而編寫的程式中,新增乙個名為number seved的屬性,並將其預設值設定為0。根據這個類建立乙個名為restaurant的例項 列印有多少人在這家餐館就餐過,然後修改這個值並再次列印它。新增乙個名為set number served 的方法,它讓你能夠設定就餐人數。呼叫這個方...
Python練習題 9 4就餐人數
9 4 就餐人數 在為完成練習 9 1 而編寫的程式中,新增乙個名為 number served 的屬性,並將其預設值設定為 0。根據這個類建立乙個名為 restaurant 的例項 列印有 多少人在這家餐館就餐過,然後修改這個值並再次列印它。新增乙個名為 set number served 的方法...