← 返回题库
中级

装饰者模式类装饰器

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    class Coffee:
        def cost(____):
            return ____
        def description(____):
            return '____'
    class MilkDecorator:
        def __init__(____):
            self._coffee = coffee
        def cost(____):
            return self._coffee.cost() + ____
        def description(____):
            return self._coffee.description() + '____'
    c = MilkDecorator(Coffee())
    print(____)

示例

输入
solve()
期望输出
7,Coffee+Milk
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码