这是在第九章,三个餐厅的问题,说第二行的冒号有一个语法错误,我不明白为什么会这样,或者错误在其他地方。可能在某个地方输入了错误的东西,但不确定在哪里,可能是我忽略了一些简单的东西。谢谢。
代码如下:
class Restaurant():
def__init__(self, name, cuisine_type):
self.name = name.title()
self.cuisine_type = cuisine_type
def describe_restaurant(self):
msg = self.name + " serves wonderful " + self.cuisine_type + "."
print("\n" + msg)
def open_restaurant(self):
msg = self.name + " is open. Come on in!"
print("\n" + msg)
mean_queen = Restaurant('the mean queen', 'pizza')
mean_queen.describe_restaurant()
ludvigs = Restaurant("ludvig's bistro", 'seafood')
ludvigs.describe_restaurant()
mango_thai = Restaurant('mango thai', 'thai food')
mango_thai.describe_restaurant()
发布于 2021-10-17 05:20:04
如果你仍然有问题,试试这个。您可能遗漏了类声明后的缩进。
class Restaurant():
def __init__(self, name, cuisine_type):
self.name = name.title()
self.cuisine_type = cuisine_type
def describe_restaurant(self):
msg = self.name + " serves wonderful " + self.cuisine_type + "."
print("\n" + msg)
def open_restaurant(self):
msg = self.name + " is open. Come on in!"
print("\n" + msg)
mean_queen = Restaurant('the mean queen', 'pizza')
mean_queen.describe_restaurant()
ludvigs = Restaurant("ludvig's bistro", 'seafood')
ludvigs.describe_restaurant()
mango_thai = Restaurant('mango thai', 'thai food')
mango_thai.describe_restaurant()
输出
The Mean Queen serves wonderful pizza.
Ludvig'S Bistro serves wonderful seafood.
Mango Thai serves wonderful thai food.
>
https://stackoverflow.com/questions/69601454
复制相似问题