鱼C论坛

 找回密码
 立即注册
查看: 1619|回复: 4

[已解决]书上第11章,11.6 组合

[复制链接]
发表于 2022-5-4 17:07:26 | 显示全部楼层
  1. class Turtle:
  2.     def __init__(self, x):
  3.         self.num = x
  4. class Fish:
  5.     def __init__(self, x):
  6.         self.num = x
  7. class Pool:
  8.     def __init__(self, x, y):
  9.         self.turtle = Turtle(x)
  10.         self.fish = Fish(y)
  11.         
  12.     def print_num(self):
  13.         print('水池里共有乌龟 %d 只,小鱼 %d 条' % (self.turtle, self.fish)) #改了这里,你这里缩进不对!
  14.    
  15. pool = Pool(1, 10)
  16. pool.print_num()
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-10-19 03:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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