너비를 다시 묻지 않고 게이블 영역을 계산할 수 있도록 calcRectArea의 너비 값을 calcTriArea로 전송해야합니다. 저는 파이썬과 프로그래밍 전반에 새로운 것이므로 어리석은 질문이라면 저를 용서하십시오. 다른 훨씬 더 고급 옵션이 있습니다하나의 함수에서 다른 함수로 값을 전송하려면 어떻게해야합니까?
def get_dimensions():
height = int(input("Enter the height: "))
width = int(input("Enter the width: "))
length = int(input("Enter the length: "))
height, width, length = get_dimensions()
# go on to pass the values to your functions
,하지만 당신이 시작할 수 있어야합니다
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()
y는이 방법으로 당신이 어떤 함수에서 제안 – Tushar
감사하는 입력 할 수있을 잡아 줄께 ... 당신이 당신의 주요 기능에 입력을 trake 해달라고, 그러나 나는 결국 변수들을 세계화시켰다. –
@JoeyCartella NO NO NO! 그러지 마. ** 언제든지 가능하면 전역을 피하십시오. –