轻松的编程学习
首页
题库
学习路径
在线商城
能力地图
下载应用
登录 / 注册
菜单
⚠️ 换一种排版,Reporter 一行没改
👁️ 2 人浏览
💬 0 人评论
❤️ 添加收藏
加一个新的排版器(只输出数字),
不许动
Reporter
和
Store
。
提交你的答案
请登录后提交答案。
去登录
← 第二步:三个形状各走一遍
⚠️ 给自己的模型体检 →
更多题目
让程序说出"你好"
让程序欢迎你
哪个命令能显示内容
哪里是指令,哪里是结果
让程序说出你的名字
这个程序会显示什么
代码编辑器
语言:
python3
c11
cpp17
Ctrl
+
Enter
运行
👩🏫 AI
▶ 运行代码
重置代码
打印代码
class Shape: def area(self): raise NotImplementedError class Rect(Shape): def __init__(self, w, h): self.w, self.h = w, h def area(self): return self.w * self.h class Formatter: def render(self, shape): return "面积=" + str(shape.area()) class ShortFormatter: # TODO: 换一种排版:只返回面积的数字(字符串形式),不加前缀 pass class Store: def __init__(self): self.box = [] def save(self, text): self.box.append(text) class Reporter: def __init__(self, fmt, store): self.fmt, self.store = fmt, store def report(self, shape): self.store.save(self.fmt.render(shape)) a, b = Store(), Store() Reporter(Formatter(), a).report(Rect(3, 4)) Reporter(ShortFormatter(), b).report(Rect(3, 4)) print(a.box[0] + "|" + b.box[0])
本次输入:
输出:
👩🏫
AI
请登录后使用 AI 老师
×
登录后可获得解题思路、提示与错误分析。
去登录
关闭
🎉
恭喜你,回答正确!
系统判定:正确
我知道了
💬 题目评论
提交
全部评论
全部评论