You have a few problems:
- First, you're defining the function
Paint_cost()
inside main()
. You can define this outside of main()
, and as long as it's defined before you call the main()
function, it will work properly.
- Second,
return
returns a value from a function, not print it.
- Third, your indentation is off. Regardless of the other two errors, Python will raise an
IndentationError
if you tried to run this.
- Fourth,
total
is undefined (you wrote it as Total
.)
- Finally, you're calling
Paint_cost()
without any arguments. You need to call it with Paint_cost(length, width, height)
.
This code works perfectly in Python 3:
def Paint_cost (length, width, height): #Find total paint cost.
perimeter = length + width * 4 #Find perimiter.
sq_ft = perimeter * height #Find total sq. ft. amount.
Paint = sq_ft / 300 #Calculate paint gallons to nearest int.
int(Paint)
total = Paint*40 #Calculate total cost.
return total #Display total.
def main():
length = float(input('Enter length: ')) #Get length.
width = float(input('Enter width: ' )) #Get width.
height = float(input('Enter height: ')) #Get height.
print(Paint_cost(length, width, height)) # Print the cost of the paint.
main()
This one is for Python 2:
def Paint_cost (length, width, height): #Find total paint cost.
perimeter = length + width * 4 #Find perimiter.
sq_ft = perimeter * height #Find total sq. ft. amount.
Paint = sq_ft / 300 #Calculate paint gallons to nearest int.
int(Paint)
total = Paint*40 #Calculate total cost.
return total #Display total.
def main():
length = float(input('Enter length: ')) #Get length.
width = float(input('Enter width: ' )) #Get width.
height = float(input('Enter height: ')) #Get height.
print Paint_cost(length, width, height) # Print the cost of the paint.
main()
In this code specifically, print
is the only change between Python 2 and 3. The function works without print in either version.
Let me know if something is wrong.