A sphere (solid) is usually considered a two-dimensional figure even though the figure is seen in three planes from its center. The main reason for this is that, a sphere is only measured using its radius. However, a hollow sphere is considered a three-di...
A sphere (solid) is usually considered a two-dimensional figure even though the figure is seen in three planes from its center. The main reason for this is that, a sphere is only measured using its radius.
However, a hollow sphere is considered a three-dimensional figure since it contains space within its spherical walls and has two different radii to measure its dimensions.
The spherical figure only has total surface area since there is only one dimension to measure the entire object. The formula to calculate the surface area of a sphere is −
Area of solid sphere − 4πr2
The volume of a sphere is considered as the mass held by the circular walls of the object. The formula to calculate volume of a sphere is given as −
Volume of solid sphere − 43πr3
Volume of hollow sphere − 43π(R−r)3
Where, R is the radius of outer sphere and r is the radius of inner sphere.
Let us look at some input output scenarios to calculate the area and volume of a sphere −
Assume the area and volume to be found is of a solid sphere −
Input: 7 // 7 is the radius Result: Area - 314.1592653589793 Volume - 359.188760060433
Assume the area and volume to be found is of a hollow sphere −
Input: (7, 5) // 7 is the outer radius, 5 is the inner radius Result: Area - 314.1592653589793 // Area is same Volume - 100.53096491487338
In the python program, we use the discussed mathematical formulae and calculate the area and volume of the sphere. We import the match library to use the pi constant.
Following is an example to find the area and volume of the spherical 3D figure −
The output is displayed as given below −
Area of the sphere: 314.1592653589793 Volume of the hollow sphere: 100.53096491487338 Volume of the solid sphere: 359.188760060433
Python also makes use of functions to improve modularity of the program. In this case, we use a function that calculates sphere’s area and volume.
In the following python program, we are calculating the area and volume of both solid and hollow spheres using a user-defined function −
On executing the above code, output is obtained as −
Area of the sphere: 314.1592653589793 Volume of the hollow sphere: 100.53096491487338 Volume of the solid sphere: 359.188760060433