简体   繁体   English

我正在从事这个初学者项目,但出现错误

[英]I'm working on this beginner project and i'm getting error

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

    def describe_restaurant(self):
        print(self.name.title() + ' serves ' + self.cuisine + ' food.')

    def open_restaurant(self):
        print(self.name.title() + ' is now open. \nCome and Have some delicious ' +self.cuisine+ ' food.' )

restaurant= Restaurant('Big Chillo', 'Italian')
restaurant.describe_restaurant()
restaurant.open_restaurant()

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

        super().__init__(cuisine_type)

    def availability(self):
        print ('These are the available cuisines ' + self.name.title())

menu =cuisine['Tiramisu \nCannoli \nPanna \ncotta \nCassata \nSemifreddo']
menu.availability()

File "D:/python project/restaurant.py", line 25, in Come and Have some delicious Italian food. 在“来吧,吃点可口的意大利美食”中的第25行,输入文件“ D:/ python project / restaurant.py”。 menu =cuisine['Tiramisu \\nCannoli \\nPanna \\ncotta \\nCassata \\nSemifreddo'] TypeError: 'type' object is not subscriptable 菜单= cuisine ['提拉米苏\\ nCannoli \\ nPanna \\ ncotta \\ nCassata \\ nSemifreddo'] TypeError:“ type”对象不可下标

使用括号()而不是方括号[]调用函数/类构造函数

menu = cuisine('Tiramisu \nCannoli \nPanna \ncotta \nCassata \nSemifreddo')

Found 3 issues with your code: 在您的代码中发现3个问题:
1. As mention by @FHTMitchell, Call functions / class constructors using parentheses () rather than square brackets [] 1.如@FHTMitchell所述,使用括号()而不是方括号[]调用函数/类的构造函数
2. You do not have Restaurant Constructor with 1 argument so I added extra parameter to code super().__init__("RestaurantName",cuisine_type) 2.您没有带1个参数的Restaurant Constructor,因此我向代码super().__init__("RestaurantName",cuisine_type)添加了额外的参数super().__init__("RestaurantName",cuisine_type)
3. self.name is String so we should not call it as a function in print of availability method changed self.name() to self.name 3. self.name是String,所以我们不应该在将self.name()更改为self.name()的可用性方法的打印self.name()其作为函数来self.name

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

    def describe_restaurant(self):
        print(self.name.title() + ' serves ' + self.cuisine + ' food.')

    def open_restaurant(self):
        print(self.name.title() + ' is now open. \nCome and Have some delicious ' +self.cuisine+ ' food.' )

restaurant= Restaurant('Big Chillo', 'Italian')
restaurant.describe_restaurant()
restaurant.open_restaurant()

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

        super().__init__("hello",cuisine_type)

    def availability(self):
        print ('These are the available cuisines ' + self.name)

menu =cuisine('Tiramisu \nCannoli \nPanna \ncotta \nCassata \nSemifreddo')
menu.availability()
menu.describe_restaurant()

The output I got is: 我得到的输出是:

 Big Chillo serves Italian food. Big Chillo is now open. Come and Have some delicious Italian food. These are the available cuisines hello Hello serves Tiramisu Cannoli Panna cotta Cassata Semifreddo food. Process finished with exit code 0 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在使用tkinter时遇到此属性错误 - I'm getting this attribute error working with tkinter 我收到“无效语法错误”,有时名称未定义此错误请帮助我初学者 - I'm getting the "invalid syntax error" and some times name is not defined this error please help im beginner in this 我该如何解决这个错误? 我正在和 django 一起做一个学校项目,但我被困住了 - How can i solve this error? I'm working with django on a school project and i'm stuck 我在带有 Tensorflow object_detection 的 python 项目中遇到此错误 - I'm getting this error in python project with Tensorflow object_detection 我在学习本教程时遇到了两个错误,我不太确定如何修复它(我是初学者) - I'm getting two errors whilst following this tutorial and I'm not very sure how to fix it (I'm a beginner) Python 错误:需要帮助解决 2 个错误(我是初学者) - Python Error: Need help resolving 2 errors (I'm a beginner) 我正在处理的这个 pygame 项目有什么问题? - What is the problem in this pygame project I'm working on? 我正在努力解决这个 python 代码(我是初学者) - I'm struggling with this this python code (I'm a beginner) Django 模型错误,现在我想从一个 charfiled 中减去另一个,但始终等于 0,就像默认值一样。 我是使用 django 的初学者 - Django models error, Now I want subtract from one charfiled other, but always equal to 0, like a default,. I'm beginner with working with django 我怎么会收到这个Django错误? - How come I'm getting this Django error?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM