Пожалуйста, помогите. У меня возникают проблемы с моей функцией getroofCalcs()
, не возвращающей переменные. В частности, переменная roofArea
на данный момент. Это базовая программа для моего введения в класс программирования, и я не могу понять, почему, когда я запускаю это, я продолжаю получать ошибку, которая не определена при вызове функции getshingleCalcs()
. Этот код находится в 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()
в блоке 'else' в вашей функции' getwallCalcs' вы указали свою переменную 'gabelArea'. Это должно быть 'gableArea'. – bunji
Почему вы перечисляете все свои переменные в комментариях? Это, откровенно говоря, не нужно. –
И ваша функция возвращает переменные, но вы не назначаете их ни на что в своей основной функции. [Вот краткая демонстрация] (http://learnpythonthehardway.org/book/ex21.html) – bunji