酷代码 AI
菜单
服务商

请编写一个基于对象的程序。数据成员包括length(长)、width(宽)、height(高).要求用成员函数实现以下功能 (1)由键盘分别输入3个长方柱的长宽高。 (2)计算长方柱的体积 (3)输出3个长方柱的体积 输入样例: 1 2 3↙ 2 3 4↙ 3 4 5↙ 输出样例: 6↙ 24↙ 60↙

class Cuboid: def __init__(self, length, width, height): self.length = length self.width = width self.height = height def calculate_volume(self): return self.length * self.width * self.height cuboids = [] for i in range(3): l, w, h = map(int, input().split()) cuboid = Cuboid(l, w, h) cuboids.append(cuboid) for cuboid in cuboids: volume = cuboid.calculate_volume() print(volume) [2024-12-11 22:58:44 | AI写代码神器 | 299点数解答]

相关提问
实用工具查看更多
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]
数独游戏 [娱乐类]
经典推箱子 [娱乐类]
AI摸鱼五子棋 [娱乐类]