Home > Back-end >  How do I get these functions to print to the screen?
How do I get these functions to print to the screen?

Time:12-14

I cannot get any of my functions to return and print anything to the screen. I am new to programming and I have been trying to do this all day. Does anyone know what I am doing wrong? I keep getting an error saying local variable 'sLastName' is assigned to but never used and I keep getting that same error on the fCost variable and fLabor variable but the other variables do not have that error. So I guess that has something to do with why it will not work?

# Paint Job Estimator

import math

def main():
    # Get user input
  fWall_Sq_Feet = getFloatInput("Enter wall space in square feet: ")
  fPrice_PerGallon = getFloatInput("Enter paint price per gallon: ")
  fFeet_PerGallon = getFloatInput("Enter feet per gallon: ")
  fLabor_Hours_PerGallon = getFloatInput("How many labor hours per gallon: ")
  fLaborCharge = getFloatInput("Labor charge per hour: ")
  sState = str(input("State job is in: "))
  sLastName = str(input("Customer Last Name: "))

# Call Functions

# Get paint int
  iGetPaint = getGallonsOfpaint(fWall_Sq_Feet, fFeet_PerGallon)

# Labor hours
  fLabor = getLaborHours(fLabor_Hours_PerGallon, iGetPaint)

# Labor cost
  fLaborCost = getLaborCost(fLabor_Hours_PerGallon, fLaborCharge)

# Paint cost
  fPaintCost = getPaintCost(iGetPaint, fPrice_PerGallon)

# State Tax
  fState = getSalesTax(sState)

# Cost estimate
  fCost = showCostEstimate(fLaborCost, fPaintCost, fState)

# Need to get number of gallons of paint
# Return a int and receives 2 floats
def getGallonsOfpaint(fTotalSquareFeet, fFeetPerGallon):
    iGallonsNeeded = math.ceil(fTotalSquareFeet/fFeetPerGallon)
    return iGallonsNeeded

# Returns the labor hours to paint the wall as a float
def getLaborHours(fLaborHoursPerGallon, fTotalGallons):
    return fLaborHoursPerGallon * fTotalGallons

# Returns the labor cost to paint the wall as a float
def getLaborCost(LaborHoursPerGallon, fLaborCharge):
    return LaborHoursPerGallon * fLaborCharge

# Returns the paint cost to paint the wall as a float
def getPaintCost(iGallonsNeeded, fPaintCost):
    return iGallonsNeeded * fPaintCost

# Show cost estimate function
def showCostEstimate(fLaborCost, fPaintCost, fState):
    print("Gallons of paint: ", iGetPaint)
    print("Hours of labor: ", format(fLabor, ".1f"))
    print("Paint charges: ", format(fPaintCost, ".2f"))
    print("Labor charges: ", format(fLaborCost, ".2f"))
    print("Tax: ", format(fState, ".2f"))
    print("Total cost: ", format(fCost, ".2f"))
    return fLaborCost   fPaintCost * fState

# Function for float input
def getFloatInput(sPromptMessage):
    fInput = 0
    while fInput <= 0:
        try:
            fInput = float(input(sPromptMessage))
        except ValueError:
            print("Input must be a number.")
    return fInput

# State function

def getSalesTax(sState):
    if sState == "CT":
         fTaxRate = .06
    elif sState == "MA":
         fTaxRate = .0625
    elif sState == "ME":
         fTaxRate = .085
    elif sState == "NH":
         fTaxRate = .0
    elif sState == "RI":
         fTaxRate = .07
    elif sState == "VT":
         fTaxRate = .06
    else:
        print("Not a valid input")

    return fTaxRate


main()   

CodePudding user response:

that because of you didn't used print to show output in main function use this code in last of main function only:

print(iGetPaint)
print(fLabor)
print(fLaborCost)
print(fPaintCost)
print(fState)
print(fCost)

CodePudding user response:

Here is the edited code, and I'll put the errors I found underneath:

# Paint Job Estimator

import math

def main():
    # Get user input
  fWall_Sq_Feet = getFloatInput("Enter wall space in square feet: ")
  fPrice_PerGallon = getFloatInput("Enter paint price per gallon: ")
  fFeet_PerGallon = getFloatInput("Enter feet per gallon: ")
  fLabor_Hours_PerGallon = getFloatInput("How many labor hours per gallon: ")
  fLaborCharge = getFloatInput("Labor charge per hour: ")
  sState = str(input("State job is in: "))
  sLastName = str(input("Customer Last Name: "))

# Call Functions

# Get paint int
  iGetPaint = getGallonsOfpaint(fWall_Sq_Feet, fFeet_PerGallon)

# Labor hours
  fLabor = getLaborHours(fLabor_Hours_PerGallon, iGetPaint)

# Labor cost
  fLaborCost = getLaborCost(fLabor_Hours_PerGallon, fLaborCharge)

# Paint cost
  fPaintCost = getPaintCost(iGetPaint, fPrice_PerGallon)

# State Tax
  fState = getSalesTax(sState)

# Cost estimate
  fCost = showCostEstimate(fLaborCost, fPaintCost, fState, iGetPaint, fLabor)
  print("Total cost: ", format(fCost, ".2f"))
# Need to get number of gallons of paint
# Return a int and receives 2 floats
def getGallonsOfpaint(fTotalSquareFeet, fFeetPerGallon):
    iGallonsNeeded = math.ceil(fTotalSquareFeet/fFeetPerGallon)
    return iGallonsNeeded

# Returns the labor hours to paint the wall as a float
def getLaborHours(fLaborHoursPerGallon, fTotalGallons):
    return fLaborHoursPerGallon * fTotalGallons

# Returns the labor cost to paint the wall as a float
def getLaborCost(LaborHoursPerGallon, fLaborCharge):
    return LaborHoursPerGallon * fLaborCharge

# Returns the paint cost to paint the wall as a float
def getPaintCost(iGallonsNeeded, fPaintCost):
    return iGallonsNeeded * fPaintCost

# Show cost estimate function
def showCostEstimate(fLaborCost, fPaintCost, fState, iGetPaint, fLabor):
    print("Gallons of paint: ", iGetPaint)
    print("Hours of labor: ", format(fLabor, ".1f"))
    print("Paint charges: ", format(fPaintCost, ".2f"))
    print("Labor charges: ", format(fLaborCost, ".2f"))
    print("Tax: ", format(fState, ".2f"))
    return fLaborCost   fPaintCost * fState

# Function for float input
def getFloatInput(sPromptMessage):
    fInput = 0
    while fInput <= 0:
        try:
            fInput = float(input(sPromptMessage))
        except ValueError:
            print("Input must be a number.")
    return fInput

# State function

def getSalesTax(sState):
    valid = False
    while(not(valid)):
      if sState == "CT":
          fTaxRate = .06
          valid = True
      elif sState == "MA":
          fTaxRate = .0625
          valid = True
      elif sState == "ME":
          fTaxRate = .085
          valid = True
      elif sState == "NH":
          fTaxRate = .0
          valid = True
      elif sState == "RI":
          fTaxRate = .07
          valid = True
      elif sState == "VT":
          fTaxRate = .06
          valid = True
      else:
          print("Not a valid input")
          sState = str(input("State job is in: "))
      return fTaxRate

main()   

Okay, this one may not be an "error", but just something in general I fixed. For the getSalesTax function, I added a while loop that would keep taking user input until the user inputted a correct state format.

For showCostEstimate(), the fCost is not yet defined, so we need to print it out after we define it and call it. Also, we need to add a few more parameters into this function since we are calling those parameters in the function.

Other than that your code looks really good! Let me know if you have any other questions/clarifications.

  • Related