2013-12-07 56 views
0

所以這是基本的砌牆計算器代碼,我有:如何將更多功能添加到石膏板工程中?

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

我改寫了一下;我想,需要在多小片廢料,可以使用更多的控制:

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意味着「僅整張紙」。房間長度應垂直於天花板託梁測量,這通常是房間較長的尺寸。

相關問題