试图让我的python函数工作,但它们工作不正常

2024-04-28 08:37:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我不能让我的python函数一起工作,也不知道为什么。我没有得到错误,但我得到我的计算零,并包括下面的代码。请提供以下信息:

def main():

# Variables in Float
wallNumber   = 0
widthOfWall  = 0.00 #float
heightOfWall = 0.00
costPerGallonPaint   = 0.00
hours  = 0.00

squareFootage = 0.00

chargeCustomerForPaint = 0.00

wallPaintedSquareFeet = 110 #const square feet of wall to be painted
gallonsOfPaint        = 0.00
roundednumberofPaint  = 0
hourRate              = 25  # const 25 dollars an hour for 100 square feet 
of paint
laborCost             = 0.00
totalCostToCustomer   = 0.00

#####################################
# Information to be provided to user
# Ask the user to enter the width of wall in feet
# Ask the user to enter the height of wall in feet
# Ask the user to to enter the cost per gallon of paint
####################################

costPerGallonPaint = float(input("Enter the cost per gallon of paint: "))
print("You entered  ",costPerGallonPaint)

for wallNumber in range(1,5):
print("Number of wall to be painted ",wallNumber)

widthOfWall = float(input("Enter the width of the wall in feet: "))
print("You entered  ",widthOfWall)

heightOfWall = float(input("Enter the height of the wall in feet: "))
print("You entered  ",heightOfWall)


######################################
#   Calculate square footage for wall to be painted
#   squareFootage = width * height
#   Charge the customer for 1 gallon of piant for every 110 square feet of 
#  wall 
# to be painted
#   Square Footage / wallPaintedSquareFeet
#   gallon is less then 110 square feet charge one gallon
#   more than one gallon then charge  for the amount of gallon
######################################

roundednumberofPaint =int(round(gallonsOfPaint + .5, 0)) #rounds up to the 
next number

def calcsquareFootage(widthOfWall, heightOfWall):
#squareFootage = widthOfWall * heightOfWall
return widthOfWall * heightOfWall

def calcgallonsOfPaint (squareFootage, wallPaintedSquareFeet):
#gallonsOfPaint = squareFootage / wallPaintedSquareFeet
return squareFootage / wallPaintedSquareFeet

def calcchargeCustomerForPaint(costPerGallonPaint, roundednumberofPaint):
return costPerGallonPaint * roundednumberofPaint
#chargeCustomerForPaint = costPerGallonPaint * roundednumberofPaint

print("Charge customer = %.02f"%calcchargeCustomerForPaint    
(costPerGallonPaint, roundednumberofPaint))

def calclaborCost(gallonsOfPaint, hourRate):
return gallonsOfPaint * hourRate

print("Cost of labor is = %.02f"%calclaborCost(gallonsOfPaint, hourRate))


#########################
#   total cost to customer
#########################

totalCostToCustomer = chargeCustomerForPaint + laborCost
print ("Total cost to customer is %.02f"%totalCostToCustomer)

Tags: ofthetoinforprintwallfeet
1条回答
网友
1楼 · 发布于 2024-04-28 08:37:35

我认为你的具体的问题是你所有的成本计算都是基于gallonsOfPaint,它被初始化为零,从未改变。您有一行代码看起来像是要更改它,但似乎被注释掉了。你知道吗

As an aside, I'm not sure in which universe a labour cost would be calculated by multiply the hourly rate by the number of gallons of paint, but I'm sure that's something you'll get round to fixing at some point :-)

相关问题 更多 >