Python Program to Calculate Volume of Dodecahedron

In the previous article, we have discussed Python Program to Calculate Area and Perimeter of Equilateral Triangle
Given a side of a Dodecahedron, the task is to find the volume of the Dodecahedron in Python.

Examples:

Example1:

Input:

Given Side = 5

Output:

The Volume of the Dodecahedron with side { 5 } is =  957.8898700780791

Example2:

Input:

Given Side = 8

Output:

The Volume of the Dodecahedron with side { 8 } is = 3923.5169078398117

Program to Calculate Volume of Dodecahedron in Python

Below are the ways to calculate the volume of the given Dodecahedron  in Python:

Volume = (15 + 7√5)*s3/4  where s is the side of the Dodecahedron

Method #1: Using Mathematical Formula (Static Input)

Approach:

  • Import the math module using the math keyword.
  • Give the side of the Dodecahedron as static input and store it in a variable.
  • Calculate the volume of the Dodecahedron using the above mathematical formula ( (15 + 7√5)*s3/4).
  • We Calculate the √5 in the above formula using the sqrt() function.
  • We can calculate the s^3 using the pow() function or ‘**‘ operator.
  • By using the above functions we calculate the volume of the Dodecahedron and store it in a variable say volDode.
  • Print the volDode value.
  • The Exit of the Program.

Below is the implementation:

# Import the math module using the math keyword.
import math
# Give the side of the Dodecahedron as static input and store it in a variable.
sideval = 5
# Calculate the volume of the Dodecahedron using the above mathematical formula
# ( (15 + 7√5)*s3/4).
# We Calculate the √5 in the above formula using the sqrt() function.
# We can calculate the s^3 using the pow() function or '**' operator.
# By using the above functions we calculate the volume of the Dodecahedron
# and store it in a variable say volDode.
volDode = (((15 + (7 * (math.sqrt(5)))) / 4) * (math.pow(sideval, 3)))
# Print the volDode value.
print(
    'The Volume of the Dodecahedron with side {', sideval, '} is = ', volDode)

Output:

The Volume of the Dodecahedron with side { 5 } is =  957.8898700780791

Method #2: Using Mathematical Formula (User Input)

Approach:

  • Import the math module using the math keyword.
  • Give the side of the Dodecahedron as user input using the int(input()) function and store it in a variable.
  • Calculate the volume of the Dodecahedron using the above mathematical formula ( (15 + 7√5)*s3/4).
  • We Calculate the √5 in the above formula using the sqrt() function.
  • We can calculate the s^3 using the pow() function or ‘**‘ operator.
  • By using the above functions we calculate the volume of the Dodecahedron and store it in a variable say volDode.
  • Print the volDode value.
  • The Exit of the Program.

Below is the implementation:

# Import the math module using the math keyword.
import math
# Give the side of the Dodecahedron as user input using the int(input()) function
# and store it in a variable.
sideval = int(input('Enter some random side of Dodecahedron = '))
# Calculate the volume of the Dodecahedron using the above mathematical formula
# ( (15 + 7√5)*s3/4).
# We Calculate the √5 in the above formula using the sqrt() function.
# We can calculate the s^3 using the pow() function or '**' operator.
# By using the above functions we calculate the volume of the Dodecahedron
# and store it in a variable say volDode.
volDode = (((15 + (7 * (math.sqrt(5)))) / 4) * (math.pow(sideval, 3)))
# Print the volDode value.
print(
    'The Volume of the Dodecahedron with side {', sideval, '} is = ', volDode)

Output:

Enter some random side of Dodecahedron = 8
The Volume of the Dodecahedron with side { 8 } is = 3923.5169078398117

Practice Python Program Examples to master coding skills and learn the fundamental concepts in the dynamic programming language Python.