鱼C论坛

 找回密码
 立即注册
查看: 2680|回复: 3

[已解决]py之类和对象

[复制链接]
发表于 2018-11-28 21:53:01 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 hhzczy 于 2018-11-28 22:00 编辑

我写了这样一段代码,运行报错(15行):
TypeError: Restaurant() takes no arguments
代码如下:

  1. class Restaurant():

  2.     def __int__(self, restaurant_name, restaurant_type):    #餐厅名称和类型
  3.         self.restaurant_name = restaurant_name
  4.         self.restaurant_type = restaurant_type

  5.     def describe_restaurant(self):    # 打印餐厅名称和类型以及描述
  6.         print(self.restaurant_name.title())
  7.         print(self.restaurant_type.title())
  8.         print('The ' + self.restaurant_name.title() + ' serves ' + self.restaurant_type.title() + '.')

  9.     def open_restaurant(self):    #营业中,来吃啊~~~
  10.         print('The ' + self.restaurant_name.title() + ' is open. Come on in!')

  11. my_restaurant = Restaurant('pizzahut', 'pizza')  #【这行报错】
复制代码


我想实现的效果是:

Pizzahut
Pizza
Pizzahut serves Pizza.
Pizzahut is open. Come on in!

百撕不得其姐,不知错在何处~~~~请大佬指教。
最佳答案
2018-11-28 22:02:14
def __init__(self, restaurant_name, restaurant_type):
查了一个i
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-11-28 22:02:14 | 显示全部楼层    本楼为最佳答案   
def __init__(self, restaurant_name, restaurant_type):
查了一个i
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-11-28 22:08:45 | 显示全部楼层
冬雪雪冬 发表于 2018-11-28 22:02
def __init__(self, restaurant_name, restaurant_type):
查了一个i

盯着15行几个字符看了半天也不知道哪儿错了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-11-28 22:16:00 | 显示全部楼层
hhzczy 发表于 2018-11-28 22:08
盯着15行几个字符看了半天也不知道哪儿错了

发现no arguments输不进参数的错误,一般都是init的问题,不是拼写错误,就是下划线不是双下划线。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-23 07:37

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表