编写程序:输入长方体的长.宽.高.求长方体的体积,

编写程序:输入长方体的长.宽.高.求长方体的体积,要求输出体积具体值时有提示语“长方体的体积”以实数的形式输出,输出时,保留宽度为6位,不足的用0补齐,小数点后面保留三位小数

class Cuboid:

def __init__(self, length, width, high):

# data must > 0

if length <= 0:

raise ValueError("length <= 0!")

if width <= 0:

raise ValueError("width <= 0!")

if high <= 0:

raise ValueError("high <= 0!")

# save the data

self.__length = length

self.__width = width

self.__high = high

# caculate and save the surface area and volume

self.__area = float(2 * (self.__length * self.__width + self.__width * self.__high + self.__high * self.__length))

self.__volume = float(self.__length * self.__width * self.__high)

def get_area(self):

return self.__area

def get_volume(self):

return self.__volume

if __name__ == '__main__':

length = float(input("Please enter the length: "))

width = float(input("Please enter the width: "))

high = float(input("Please enter the high: "))

TestCuboid = Cuboid(length, width, high)

print("Surface area is: ", TestCuboid.get_area())

print("Volume is: ", TestCuboid.get_volume())

 

long = float(input('输入长方体的长:'))
width = float(input('输入长方体的宽:'))
height = float(input('输入长方体的高:')) 
print('长方体的体积:%06.3f'%(long*width*height))

长度为6,三位小数

只需要把公式带进去就行v=abc

Height = float(input('>')) 
Long = float(input('>'))
Width = float(input('>'))
 
Result = (Height*Width*Long)
print(f"长方体的体积为{Result}.")

代码如上,万望采纳。

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632