0

Please help. I am having issues with my getroofCalcs() function not returning variables. Specifically the roofArea variable at the moment. This is a basic program for my intro to programming class and I can not figure out why when I run this I keep getting the error that roofArea is not defined when I call for the getshingleCalcs() function. This code is in Python.

# Stick Built Garage Estimator
# Written by: John Ruehs

#Initialization Variables

#Declare doAgain

#Input Variables

#Declare length
#Declare width
#Declare studSpace
#Declare wallHeight
#Declare roofPitch
#Declare overHang
#Declare bigGarageDoor
#Declare smallGarageDoor
#Declare entryDoor
#Declare window

#Calculated Variables

#Declare topTiePlate
#Declare bottomPlate
#Declare studs
#Declare wallSheathing
#Declare roofSheathing
#Declare shingles
#Declare shingleStarter
#Declare ridgeCap
#Declare roofArea
#Declare rakeLength
#Declare studAdj
#Declare botPlateAdj
#Declare wallAreaAdj
#Declare gableArea

import math

def main():
    doAgain = "yes"
    if doAgain == "yes":
        length, width, studSpace, wallHeight, roofPitch, overHang, bigGarageDoor, smallGarageDoor, entryDoor, windows = getinputs()
        getframeCalcs(length, width, studSpace, bigGarageDoor, smallGarageDoor, entryDoor, windows)
        getwallCalcs(length, width, wallHeight, bigGarageDoor, smallGarageDoor, entryDoor, roofPitch)#need to put variables needed here
        getroofCalcs(length, width, roofPitch, overHang)#need to put variables needed here
        getshingleCalcs(length, roofArea, rakeLength)#need to put variables needed here
        display(topTiePlate, bottomPlate, studs, wallSheathing, roofSheathing, shingles, shingleStarter, ridgeCap, rakeLength)#need to put variables needed here
        doAgain = input("Do you want to run this again('yes' or 'no')?")
    else:
        print("")


def getinputs():
    length = float(input("Enter the length of the building: "))
    width = float(input("Enter the width of the building: "))
    studSpace = float(input("Enter the stud spacing: "))
    wallHeight = float(input("Enter the wall height: "))
    roofPitch = input("Enter the roof pitch: ")
    overHang = float(input("Enter the over-hang in inches: "))
    bigGarageDoor = int(input("Enter the number of 16' garage doors: "))
    smallGarageDoor = int(input("Enter the number of 9' garage doors: "))
    entryDoor = int(input("Enter the number of entry doors: "))
    windows = int(input("Enter the number of windows that are smaller than 3' wide: "))
    return length, width, studSpace, wallHeight, roofPitch, overHang, bigGarageDoor, smallGarageDoor, entryDoor, windows

def getframeCalcs(length, width, studSpace, bigGarageDoor, smallGarageDoor, entryDoor, windows):
    studAdj = ((bigGarageDoor*-7)+(smallGarageDoor*-3)+(entryDoor*2)+(windows*5))
    botPlateAdj = ((bigGarageDoor*-16)+(smallGarageDoor*-9)+(entryDoor*-3))
    studs = math.ceil((((((((length*2)+(width*2))*12)/studSpace)+8)*1.1)+studAdj))
    topTiePlate = math.ceil((((length*2)+(width*2))/16)*2)
    bottomPlate = math.ceil(((((length*2)+(width*2))+botPlateAdj)/16))
    return studs, topTiePlate, bottomPlate

def getwallCalcs(length, width, wallHeight, bigGarageDoor, smallGarageDoor, entryDoor, roofPitch):
    wallAreaAdj = ((bigGarageDoor*-112)+(smallGarageDoor*-63)+(entryDoor*-21.77))
    if roofPitch == "1/12":
        gableArea = math.ceil(((((width/2)+0.5)*1)/12)*(((width/2)+0.5))*2)
    elif roofPitch == "2/12":
        gableArea = math.ceil(((((width/2)+0.5)*2)/12)*(((width/2)+0.5))*2)
    elif roofPitch == "3/12":
        gableArea = math.ceil(((((width/2)+0.5)*3)/12)*(((width/2)+0.5))*2)
    elif roofPitch == "4/12":
        gableArea = math.ceil(((((width/2)+0.5)*4)/12)*(((width/2)+0.5))*2)
    elif roofPitch == "5/12":
        gableArea = math.ceil(((((width/2)+0.5)*5)/12)*(((width/2)+0.5))*2)
    elif roofPitch == "6/12":
        gableArea = math.ceil(((((width/2)+0.5)*6)/12)*(((width/2)+0.5))*2)
    elif roofPitch == "7/12":
        gableArea = math.ceil(((((width/2)+0.5)*7)/12)*(((width/2)+0.5))*2)
    elif roofPitch == "8/12":
        gableArea = math.ceil(((((width/2)+0.5)*8)/12)*(((width/2)+0.5))*2)
    elif roofPitch == "9/12":
        gableArea = math.ceil(((((width/2)+0.5)*9)/12)*(((width/2)+0.5))*2)
    elif roofPitch == "10/12":
        gableArea = math.ceil(((((width/2)+0.5)*10)/12)*(((width/2)+0.5))*2)
    elif roofPitch == "11/12":
        gableArea = math.ceil(((((width/2)+0.5)*11)/12)*(((width/2)+0.5))*2)
    else:
        gabelArea = math.ceil(((((width/2)+0.5)*12)/12)*(((width/2)+0.5))*2)
    wallSheathing = math.ceil(((((((length*2)+(width*2))*wallHeight)+gableArea)+wallAreaAdj)/32))
    return wallSheathing

def getroofCalcs(length, width, roofPitch, overHang):
    if roofPitch == "1/12":
        roofArea = math.ceil((((((((((width/2)+(overHang/12))*1)/12)**2)+(((width/2)+(overHang/12))**2))**.5)*length)*2))
    elif roofPitch == "2/12":
        roofArea = math.ceil((((((((((width/2)+(overHang/12))*2)/12)**2)+(((width/2)+(overHang/12))**2))**.5)*length)*2))
    elif roofPitch == "3/12":
        roofArea = math.ceil((((((((((width/2)+(overHang/12))*3)/12)**2)+(((width/2)+(overHang/12))**2))**.5)*length)*2))
    elif roofPitch == "4/12":
        roofArea = math.ceil((((((((((width/2)+(overHang/12))*4)/12)**2)+(((width/2)+(overHang/12))**2))**.5)*length)*2))
    elif roofPitch == "5/12":
        roofArea = math.ceil((((((((((width/2)+(overHang/12))*5)/12)**2)+(((width/2)+(overHang/12))**2))**.5)*length)*2))
    elif roofPitch == "6/12":
        roofArea = math.ceil((((((((((width/2)+(overHang/12))*6)/12)**2)+(((width/2)+(overHang/12))**2))**.5)*length)*2))
    elif roofPitch == "7/12":
        roofArea = math.ceil((((((((((width/2)+(overHang/12))*7)/12)**2)+(((width/2)+(overHang/12))**2))**.5)*length)*2))
    elif roofPitch == "8/12":
        roofArea = math.ceil((((((((((width/2)+(overHang/12))*8)/12)**2)+(((width/2)+(overHang/12))**2))**.5)*length)*2))
    elif roofPitch == "9/12":
        roofArea = math.ceil((((((((((width/2)+(overHang/12))*9)/12)**2)+(((width/2)+(overHang/12))**2))**.5)*length)*2))
    elif roofPitch == "10/12":
        roofArea = math.ceil((((((((((width/2)+(overHang/12))*10)/12)**2)+(((width/2)+(overHang/12))**2))**.5)*length)*2))
    elif roofPitch == "11/12":
        roofArea = math.ceil((((((((((width/2)+(overHang/12))*11)/12)**2)+(((width/2)+(overHang/12))**2))**.5)*length)*2))
    else:
        roofArea = math.ceil((((((((((width/2)+(overHang/12))*12)/12)**2)+(((width/2)+(overHang/12))**2))**.5)*length)*2))

    roofSheathing = math.ceil(roofArea/32)

    if roofPitch == "1/12":
        rakeLength = math.ceil((((((((width/2)+(overHang/12))*1)/12)**2)+(((width/2)+(overHang/12))**2))**.5))
    elif roofPitch == "2/12":
        rakeLength = math.ceil((((((((width/2)+(overHang/12))*2)/12)**2)+(((width/2)+(overHang/12))**2))**.5))
    elif roofPitch == "3/12":
        rakeLength = math.ceil((((((((width/2)+(overHang/12))*3)/12)**2)+(((width/2)+(overHang/12))**2))**.5))
    elif roofPitch == "4/12":
        rakeLength = math.ceil((((((((width/2)+(overHang/12))*4)/12)**2)+(((width/2)+(overHang/12))**2))**.5))
    elif roofPitch == "5/12":
        rakeLength = math.ceil((((((((width/2)+(overHang/12))*5)/12)**2)+(((width/2)+(overHang/12))**2))**.5))
    elif roofPitch == "6/12":
        rakeLength = math.ceil((((((((width/2)+(overHang/12))*6)/12)**2)+(((width/2)+(overHang/12))**2))**.5))
    elif roofPitch == "7/12":
        rakeLength = math.ceil((((((((width/2)+(overHang/12))*7)/12)**2)+(((width/2)+(overHang/12))**2))**.5))
    elif roofPitch == "8/12":
        rakeLength = math.ceil((((((((width/2)+(overHang/12))*8)/12)**2)+(((width/2)+(overHang/12))**2))**.5))
    elif roofPitch == "9/12":
        rakeLength = math.ceil((((((((width/2)+(overHang/12))*9)/12)**2)+(((width/2)+(overHang/12))**2))**.5))
    elif roofPitch == "10/12":
        rakeLength = math.ceil((((((((width/2)+(overHang/12))*10)/12)**2)+(((width/2)+(overHang/12))**2))**.5))
    elif roofPitch == "11/12":
        rakeLength = math.ceil((((((((width/2)+(overHang/12))*11)/12)**2)+(((width/2)+(overHang/12))**2))**.5))
    else:
        rakeLength = math.ceil((((((((width/2)+(overHang/12))*12)/12)**2)+(((width/2)+(overHang/12))**2))**.5))
    return roofArea, roofSheathing, rakeLength

def getshingleCalcs(length, roofArea, rakeLength):
    shingles = math.ceil(((roofArea/100)*3))
    shingleStarter = math.ceil((((rakeLength*4)+(length*2))/120))
    ridgeCap = math.ceil(length/20)
    return shingles, shingleStarter, ridgeCap

def display(topTiePlate, bottomPlate, studs, wallSheathing, roofSheathing, shingles, shingleStarter, ridgeCap, rakeLength):
    print("")
    print("16' Top Plate/Tie Plate: ", topTiePlate)
    print("16' Bottom Plate: ", bottomPlate)
    print("Studs: ", studs)
    print("4'x8' Wall Sheathing: ", wallSheathing)
    print("4'x8' Roof Sheathing: ", roofSheathing)
    print("Rake Length (Rounded Up): ", rakeLength)
    print("Bundles of Shingles: ", shingles)
    print("Bundles of Shingle Starter: ", shingleStarter)
    print("Bundles of Ridge Cap: ", ridgeCap)
    print("")
    print("")

main()
7
  • in the else block in your getwallCalcs function you spelled your variable gabelArea. It should be gableArea. Commented Aug 6, 2016 at 4:16
  • Why are you listing all your variables in the comments? It's, quite frankly, unnecessary. Commented Aug 6, 2016 at 4:18
  • 1
    And your function is returning variables but you're not assigning them to anything in your main function. Here's a quick demonstration Commented Aug 6, 2016 at 4:24
  • You do realize you can get rid of all those cancerous if-elif blocks right? Your code is hard to read and contains a lot of redundant code which can easily be removed to allow for much cleaner and shorter code. Commented Aug 6, 2016 at 5:49
  • Evil Tak, I'm in my first ever coding class dealing with python (which I have never dealt with before). Each of those if-elif statement blocks are there because I do not know how to do what I want to do differently. Commented Aug 6, 2016 at 12:50

1 Answer 1

1

getroofCalcs() is returning a value - it's returning a tuple consisting of the three calculated values. The problem is, however, that the return value is not bound to any variable and so is lost. You can change the code where the call to getroofCalcs() is made in main() to bind the return value of the function to a variable:

    result = getroofCalcs(length, width, roofPitch, overHang)#need to put variables needed here

This will bind to the variable result the tuple returned by getroofCalcs(). It's also possible to unpack the tuple directly into individual variables like this:

    roofArea, roofSheathing, rakeLength = getroofCalcs(length, width, roofPitch, overHang)

Now the call to getshingleCalcs() should work.

N.B. there is a similar problem with the call to getshingleCalcs() where the return value is lost because it is not bound to any variable(s). You should also change that line to:

    shingles, shingleStarter, ridgeCap = getshingleCalcs(length, roofArea, rakeLength)
Sign up to request clarification or add additional context in comments.

2 Comments

mhawke, thank you. I don't know why I didn't think of that and I should have remembered that.
@JohnRuehs: no problem. You might want to consider accepting this answer if it has solved and explained the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.