Мне нужно передать значение ширины в calcRectArea в calcTriArea, чтобы я мог вычислить область фронтона, не запрашивая ширину второй раз. Я очень новичок в Python и программировании вообще, так что простите меня, если это глупый вопрос.Как передать значение одной функции другой функции?
def main():
'''
main adds rectangular area and triangular area to compute the total area
'''
rectarea=0
rectarea=calcRectArea(rectarea)
print("Rectangular area is now",rectarea)
triarea=0
triarea=calcTriArea(triarea)
print("Triangular area is now",triarea)
totalarea=triarea+rectarea
print("The total area of the first house is",totalarea)
print("For the second house: ")
rectarea2=0
rectarea2=calcRectArea(rectarea2)
print("Rectangular area of second house is now",rectarea2)
triarea2=0
triarea2=calcTriArea(triarea2)
print("Triangular area of the second house is now",triarea2)
totalarea2=triarea2+rectarea2
print("The total area of the second house is",totalarea2)
totalbothhouses=totalarea+totalarea2
print("The combined area of both houses is",totalbothhouses)
def calcRectArea(RectAreaTotal):
'''
calcRectArea prompts the user to enter width, height, and length, computes the
front and side areas, and adds them to compute rectangular area
'''
width=input("Enter the width: ")
width=int(width)
height=input("Enter the height: ")
height=int(height)
length=input("Enter the length: ")
length=int(length)
front=(width*height)
side=(length*height)
RectAreaTotal=(front*2)+(side*2)
return RectAreaTotal
def calcTriArea(totalgablearea):
'''
calcTriArea has the user enter the gable height and computes triangular area
'''
gableheight=input("Enter the gable height: ")
gableheight=int(gableheight)
totalgablearea=(gableheight)
return totalgablearea
main()
у разве Вы trake входы в основной функции ... таким образом, вы Willl быть в состоянии эти входы в любой функции – Tushar
Спасибо за предложения, но я закончил просто глобализацию переменных. –
@JoeyCartella НЕТ НЕТ НЕТ! Не делай этого. ** ВСЕГДА ** избегайте глобализации, когда можете. –