In the previous article, we have discussed Python Program to Find Sum of Arithmetic Progression Series
Surface Area of a Cube :
If we know the length of an edge in a Cube, we can use the following formula to calculate the surface area of a Cube:
Cube Surface Area = 6S²
In which S= length of any side of a Cube
A square’s area = S². Surface Area of a Cube = 6S² because the Cube is made up of 6 equal squares.
The volume of a Cube :
Volume refers to the amount of space inside the Cube. If we know the length of any edge of a Cube, we can use the following
Formula to calculate the Volume of the Cube: S*S*S*
Examples:
Example 1:
Input:
Given side length of a cube = 12
Output:
The given surface Area of a Cube with side length [ 12 ]= 864.000 The given volume of a Cube with side length [ 12 ]= 1728.000 The given lateral surface area of a Cube with side lngth [ 12 ]= 576.000
Example 2:
Input:
Given side length of a cube = 4
Output:
The given surface Area of a Cube with side length [ 4 ]= 96.000 The given volume of a Cube with side length [ 4 ]= 64.000 The given lateral surface area of a Cube with side lngth [ 4 ]= 64.000
Program to Find Volume and Surface Area of a Cube in Python
Below are the ways to find the surface area, volume, and lateral surface for a given side of a cube:
Method #1: Using Mathematical Formula (Static Input)
Approach:
- Give the length of the side of a cube as static input and store it in a variable.
- Calculate the surface area of a given cube using the above given mathematical formula and store it in another variable.
- Calculate the volume of a given cube using the above given mathematical formula and store it in another variable.
- Calculate the lateral surface area of a given cube using the above given mathematical formula and store it in another variable.
- Print the surface area of a given cube.
- Print the volume of a given cube.
- Print the lateral surface area of a given cube.
- The Exit of the Program.
# Give the length of the side of a cube as static input and store it in a variable.
cube_side = 7
# Calculate the surface area of a given cube using the above given mathematical formula
# and store it in another variable.
surf_area = 6 * (cube_side * cube_side)
# Calculate the volume of a given cube using the above given mathematical formula and
# store it in another variable.
Volum = cube_side * cube_side * cube_side
# Calculate the lateral surface area of a given cube using the above given mathematical
# formula and store it in another variable.
Laterl_surfcarea = 4 * (cube_side * cube_side)
# Print the surface area of a given cube.
print(
"The given surface Area of a Cube with side length [", cube_side, "]= %.3f" % surf_area)
# Print the volume of a given cube.
print(
"The given volume of a Cube with side length [", cube_side, "]= %.3f" % Volum)
# Print the lateral surface area of a given cube.
print(
"The given lateral surface area of a Cube with side lngth [", cube_side, "]= %.3f" % Laterl_surfcarea)
Output:
The given surface Area of a Cube with side length [ 7 ]= 294.000 The given volume of a Cube with side length [ 7 ]= 343.000 The given lateral surface area of a Cube with side lngth [ 7 ]= 196.000
Method #2: Using Mathematical Formula (User Input)
Approach:
- Give the length of the side of a cube as user input using the float(input()) function and store it in a variable.
- Calculate the surface area of a given cube using the above given mathematical formula and store it in another variable.
- Calculate the volume of a given cube using the above given mathematical formula and store it in another variable.
- Calculate the lateral surface area of a given cube using the above given mathematical formula and store it in another variable.
- Print the surface area of a given cube.
- Print the volume of a given cube.
- Print the lateral surface area of a given cube.
- The Exit of the Program.
Below is the implementation:
# Give the length of the side of a cube as user input using the float(input()) function
# and store it in a variable.
cube_side = float(input("Enter some random number = "))
# Calculate the surface area of a given cube using the above given mathematical formula
# and store it in another variable.
surf_area = 6 * (cube_side * cube_side)
# Calculate the volume of a given cube using the above given mathematical formula and
# store it in another variable.
Volum = cube_side * cube_side * cube_side
# Calculate the lateral surface area of a given cube using the above given mathematical
# formula and store it in another variable.
Laterl_surfcarea = 4 * (cube_side * cube_side)
# Print the surface area of a given cube.
print(
"The given surface Area of a Cube with side length [", cube_side, "]= %.3f" % surf_area)
# Print the volume of a given cube.
print(
"The given volume of a Cube with side length [", cube_side, "]= %.3f" % Volum)
# Print the lateral surface area of a given cube.
print(
"The given lateral surface area of a Cube with side lngth [", cube_side, "]= %.3f" % Laterl_surfcarea)
Output:
Enter some random number = 5.5 The given surface Area of a Cube with side length [ 5.5 ]= 181.500 The given volume of a Cube with side length [ 5.5 ]= 166.375 The given lateral surface area of a Cube with side lngth [ 5.5 ]= 121.000
Explore more instances related to python concepts from Python Programming Examples Guide and get promoted from beginner to professional programmer level in Python Programming Language.