📌  相关文章
📜  Python |长方体总表面积的百分比增加

📅  最后修改于: 2021-04-22 00:59:14             🧑  作者: Mango

给定长方体L ,宽度B和高度H的长方体,任务是找到长方体,总长和高度按固定百分比增加时长方体总表面积的增加百分比。

例子:

Input :
L = 20, B = 30, H = 50, l = 10 %, b = 12 %, h = 15 %
Output :
26.97 %

Input :
L = 40, B = 60, H = 15, l = 5 %, b = 7 %, h = 12 %
Output :
14.88 %

代码:用于查找长方体总表面积增加的Python代码。

# Function to return the percentage increase 
# in the total surface area of the cuboid 
# Total surface area of a cuboid = 2(L * B) + (L * H) + (B * H)
def increaseIntsa(L, B, H, l, b, h):
    oldsurfacearea = 2*((L * B) + (L * H) + (B * H))
    newsurfacearea = 2*((L + (L * l * 0.01))*(B + (B * b*0.01)) + 
                        (L + (L * l * 0.01))*(H + (H * h*0.01)) +
                        (B + (B * b * 0.01))*(H + (H * h*0.01)))
    increase = (newsurfacearea - oldsurfacearea)
    increasepercent = (increase / oldsurfacearea) * 100
    return(increasepercent)
  
# Cuboid dimnesions
L = 20
B = 30
H = 50
  
# percentage increase
l = 10
b = 12
h = 15
print(increaseIntsa(L, B, H, l, b, h), "%") 

输出 :

26.974193548387092 %