所以这是我的基本干墙计算器代码:
def drywall_sheets_required(width,depth,height,useScrap=False):
if useScrap==False:
sheetSize1=(4*8)
surfacearea1=(width*depth)
surfacearea2=(width*height)
surfacearea3=(height*depth)
TotalArea=surfacearea1+surfacearea2+surfacearea2+surfacearea3+surfacearea3
ss1=surfacearea1/sheetSize1
TSS1=ss1
ss3=surfacearea2/sheetSize1
TSS2=ss3+ss3
ss5=surfacearea3/sheetSize1
TSS3=ss5+ss5
Dsum=TSS1+TSS2+TSS3
print(TotalArea)
print("You need",int(Dsum)+1,"drywall sheets for the room")
基本上它会计算四面墙和天花板的面积,并将其除以干墙的面积为32.但是我要像这样扩展这个脚本:
def drywall_sheets_required(width,depth,height,sheetSize=(4,8),useScrap=True):
如果useScrap为true,那么任何剩余的干砌墙都可以重复使用。当useScrap为false时,则必须丢弃所有废料。对于我当前的代码,如果总面积不是整数,则添加一个。所以我猜这意味着useScrap是假的。
另外,有没有办法可以改变干墙板的方向?标准尺寸是(4,8),但是如果我将其改为(8,4)它会产生显着的差异吗?
答案 0 :(得分:0)
我重写了一下;我认为需要更多地控制一块废料的使用范围:
from math import ceil
DEBUG = True
if DEBUG:
def debug_print(x): print(x)
else:
def debug_print(x): pass
def drywall_sheets_per_surface(surface_width, surface_height, div_sheet_width_by, div_sheet_height_by, sheet_width, sheet_height):
"""
Calculate the number of sheets of drywall needed to finish a rectangular surface
Params same as for drywall_sheets_per_room
"""
w = ceil(float(div_sheet_width_by ) * surface_width / sheet_width ) / div_sheet_width_by
h = ceil(float(div_sheet_height_by) * surface_height / sheet_height) / div_sheet_height_by
debug_print('Width: {}\' Height: {}\' -> {} sheets ({}\') wide x {} sheets ({}\') high = {} sheets'.format(surface_width, surface_height, w, w*sheet_width, h, h*sheet_height, w*h))
return w*h
def drywall_sheets_per_room(room_width, room_length, room_height, div_sheet_width_by=5, div_sheet_height_by=2, sheet_width=8, sheet_height=4):
"""
Calculate the number of sheets of drywall needed to finish a room
Given:
room_width float: room width in feet
room_length float: room length in feet
room_height float: room height in feet
div_sheet_width_by int: number of times you are willing to split the width of a sheet
div_sheet_height_by int: number of times you are willing to split the height of a sheet
sheet_width float: sheet width in feet
sheet_height float: sheet height in feet
Returns:
float: number of sheets required
"""
sides = 2. * drywall_sheets_per_surface(room_length, room_height, div_sheet_width_by, div_sheet_height_by, sheet_width, sheet_height)
ends = 2. * drywall_sheets_per_surface(room_width, room_height, div_sheet_width_by, div_sheet_height_by, sheet_width, sheet_height)
ceiling = drywall_sheets_per_surface(room_length, room_width, div_sheet_width_by, div_sheet_height_by, sheet_width, sheet_height)
debug_print('Total of {} sheets required.'.format(sides + ends + ceiling))
return sides + ends + ceiling
默认参数假设您不会重复使用小于16英寸宽(与墙壁螺柱间距匹配)或24英寸高(半张高)的任何废料。您可以通过修改div_sheet_x_by
参数来更改最小件数;将它们都设置为1表示“仅限整张纸”。房间长度应垂直于天花板托梁测量,通常是较长的房间尺寸。