Python 인터프리터는 paintRequiredCeiling이 정의되지 않는다고 말합니다. 코드에서 오류를 찾을 수 없었습니다. 목표는 프로그램이 사용자로부터 입력을받은 다음 페인트 작업에 필요한 비용/시간을 계산하는 것입니다..ceil() 수학 함수가 작동하지 않습니까?
import math
def main():
# Prompts user for sq and paint price
totalArea = float(input("Total sq of space to be painted? "))
paintPrice = float(input("Please enter the price per gallon of paint. "))
perHour = 20
hoursPer115 = 8
calculate(totalArea, paintPrice, perHour, hoursPer115)
printFunction()
def calculate(totalArea, paintPrice, perHour, hoursPer115):
paintRequired = totalArea/115
paintRequiredCeiling = math.ceil(paintRequired)
hoursRequired = paintRequired * 8
costOfPaint = paintPrice * paintRequiredCeiling
laborCharges = hoursRequired * perHour
totalCost = laborCharges + costOfPaint
def printFunction():
print("The numbers of gallons of paint required:", paintRequiredCeiling)
print("The hours of labor required:", format(hoursRequired, '.1f'))
print("The cost of the paint: $", format(costOfPaint, '.2f'), sep='')
print("Total labor charges: $", format(laborCharges, '.2f'), sep='')
print("Total cost of job: $", format(totalCost, '.2f'), sep='')
main()
변수는'calculate' 함수에 국한되어 있으므로 할당 한 값은'printFunction'에 표시되지 않습니다. – Barmar
'calculate' 함수의 지역 변수입니다. 그것을 돌려주고, 파라미터로서'printFunction'에 전파 할 필요가 있습니다. – BartoszKP
오류 메시지가 표시되면 오류의 원인과 오류의 원인을 정확히 알려줘야합니다. 오류를 찾기 위해 코드를 실행하거나 연구하지 않아도됩니다. – Gabe