我不能让我的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)
我认为你的具体的问题是你所有的成本计算都是基于
gallonsOfPaint
,它被初始化为零,从未改变。您有一行代码看起来像是要更改它,但似乎被注释掉了。你知道吗相关问题 更多 >
编程相关推荐