200k views
1 vote
Define a function pyramid_volume with parameters base_length, base_width, and pyramid_height, that returns the volume of a pyramid with a rectangular base. Sample output with inputs: 4.5 2.1 3.0

User Vesan
by
4.5k points

1 Answer

3 votes

Answer:

def pyramid_volume(base_length,base_width,pyramid_height):

return base_length * base_width * pyramid_height/3

length = float(input("Length: "))

width = float(input("Width: "))

height = float(input("Height: "))

print("{:.2f}".format(pyramid_volume(length,width,height)))

Step-by-step explanation:

This line declares the function along with the three parameters

def pyramid_volume(base_length,base_width,pyramid_height):

This line returns the volume of the pyramid

return base_length * base_width * pyramid_height/3

The main starts here

The next three lines gets user inputs for length, width and height

length = float(input("Length: "))

width = float(input("Width: "))

height = float(input("Height: "))

This line returns the volume of the pyramid in 2 decimal places

print("{:.2f}".format(pyramid_volume(length,width,height)))

User Abiezer
by
4.2k points