Python Programming Exercises,
Gently Explained
135
Exercise #4: Area & Volume
def area(length, width):
# Return the product of the length and width:
return length * width
def perimeter(length, width):
# Return the sum of the length twice and the width twice:
return length * 2 + width * 2
def volume(length, width, height):
# Return the product of the length, width, and height:
return length * width * height
def surfaceArea(length, width, height):
# Return the sum of the area of each of the six sides:
return ((length * width) + (length * height) + (width * height)) * 2
Dostları ilə paylaş: