OOP 长方柱类(类和对象)Python实现

题目描述

编写基于对象的程序,求长方柱(Bulk)的体积。数据成员包括长(length)、宽(width)、高(heigth)、体积,要求用成员函数实现下面的功能:

(1)由键盘输入长方柱的长、宽、高;

(2)计算长方柱的体积(volume)和表面积(areas);

(3)输出这长方柱的体积和表面积。

输入

长方柱的长、宽、高

输出

长方柱的体积和表面积

输入样例1

2 3 4

输出样例1

24
52

AC代码

class Bulk:
    def function(self):
        length,width,heigth=map(int,input().split())
        print(length*width*heigth,2*(length*width+width*heigth+heigth*length),sep='\n')
bulk=Bulk()
bulk.function()

猜你喜欢

转载自blog.csdn.net/weixin_62264287/article/details/125756543