Python program for volume of Pyramid

A pyramid is a 3-dimensional geometric shape formed by connecting all the corners of a polygon to a central apex There are many types of pyramids. Most often, they are named after the type of base they have. look at some common types of pyramids below.

Python program that calculates the volume of a pyramid based on user input for height and base dimensions: 

 

# Python program to calculate the volume of a pyramid

# ask user for input
height = float(input("Enter the height of the pyramid: "))
base_length = float(input("Enter the length of the base of the pyramid: "))
base_width = float(input("Enter the width of the base of the pyramid: "))

# calculate the volume of the pyramid
volume = (1/3) * base_length * base_width * height

# print the result
print("The volume of the pyramid is: ", volume)

Here's how the program works:

  1. The user is prompted to enter the height, base length, and base width of the pyramid.
  2. The program uses the input values to calculate the volume of the pyramid using the formula: (1/3) * base length * base width * height.
  3. The calculated volume is stored in the variable 'volume'.
  4. Finally, the program prints out the calculated volume of the pyramid.

Note that the input function is used to get user input. The float() function is used to convert the user input from a string to a floating-point number, which can be used for mathematical calculations. The print() function is used to display the output of the program.

Submit Your Programming Assignment Details