Bitte helfen Sie. Ich habe Probleme mit meiner getroofCalcs()
Funktion, die keine Variablen zurückgibt. Speziell die roofArea
Variable im Moment. Dies ist ein grundlegendes Programm für meine Einführung in die Programmierklasse und ich kann nicht herausfinden, warum, wenn ich dies ausführe ich immer den Fehler, dass roofArea
nicht definiert ist, wenn ich für die getshingleCalcs()
Funktion aufrufen. Dieser Code ist in Python.Funktion gibt keinen Wert zurück
# 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()
Im 'else' Block in Ihrer' getwallCalcs' Funktion haben Sie Ihre Variable 'gabelArea' geschrieben. Es sollte 'GableArea' sein. – bunji
Warum listen Sie alle Ihre Variablen in den Kommentaren auf? Es ist, ehrlich gesagt, unnötig. –
Und Ihre Funktion gibt Variablen zurück, aber Sie ordnen sie nichts in Ihrer Hauptfunktion zu. [Hier ist eine kurze Demonstration] (http://learnpythontehardway.org/book/ex21.html) – bunji