In the previous article, we have discussed Python Program to Compute x^n/n!
Math Module :
Python’s math module is a built-in module. By importing this module, we can perform mathematical computations.
Numerous mathematical operations like ceil( ),floor( ),factorial( ),mod( ),value of pi ,…..etc .can be computed with the help of math module.
Hemisphere:
The word hemisphere can be broken down into hemi and sphere, where hemi means half and sphere is a 3D geometric shape used in mathematics.
As a result, a hemisphere is a three-dimensional geometric shape that is half of a sphere, with one side flat and the other as a circular bowl.
Formula to calculate the surface area of a Hemisphere:
surface area = 3????r²
In which, r is the radius of the hemisphere.
Examples:
Example1:
Input:
Given Hemisphere's Radius = 9
Output:
The Surface Area of the given Hemisphere with radius { 9 } = 763.02 The Volume of the given Hemisphere with radius { 9 } = 1526.04
Example2:
Input:
Given Hemisphere's Radius = 12.5
Output:
The Surface Area of the given Hemisphere with radius { 12.5 } = 1471.875 The Volume of the given Hemisphere with radius { 12.5 } = 4088.5416666666665
Program to Calculate the Surface Area and Volume of a Hemisphere in Python
Below are the ways to Calculate the surface area and volume of a hemisphere with the given hemisphere’s radius :
Method #1: Using Mathematical Formula (Static Input)
Approach:
- Import the math module using the import keyword.
- Give the hemisphere’s radius as static input and store it in a variable.
- Take a variable and initialize it with the value of pi as 3.14.
- Calculate the surface area of the given hemisphere using the above given mathematical formula and math.pow() function.
- Store it in another variable.
- Calculate the volume of the given hemisphere using the above given mathematical formula and math.pow() function.
- Store it in another variable.
- Print the hemisphere’s surface area with the given radius of the hemisphere.
- Print the hemisphere’s perimeter with the given radius of the hemisphere.
- The Exit of the program.
Below is the implementation:
# Import the math module using the import keyword. import math # Give the hemisphere's radius as static input and store it in a variable. gvn_radus = 9 # Take a variable and initialize it with the value of pi as 3.14 . valof_pi = 3.14 # Calculate the surface area of the given hemisphere using the above given mathematical # formula and math.pow() function. # Store it in another variable. hemi_surfceara = 3*valof_pi*math.pow(gvn_radus, 2) # Calculate the volume of the given hemisphere using the above given mathematical formula # and math.pow() function. # Store it in another variable. hemi_volum = (2.0/3.0)*valof_pi*math.pow(gvn_radus, 3) # Print the hemisphere's surface area with the given radius of the hemisphere. print("The Surface Area of the given Hemisphere with radius {", gvn_radus, " } = ", hemi_surfceara) # Print the hemisphere's perimeter with the given radius of the hemisphere. print("The Volume of the given Hemisphere with radius {", gvn_radus, "} = ", hemi_volum)
Output:
The Surface Area of the given Hemisphere with radius { 9 } = 763.02 The Volume of the given Hemisphere with radius { 9 } = 1526.04
Method #2: Using Mathematical Formula (User Input)
Approach:
- Import the math module using the import keyword.
- Give the hemisphere’s radius as user input using the float(input()) function and store it in a variable.
- Take a variable and initialize it with the value of pi as 3.14.
- Calculate the surface area of the given hemisphere using the above given mathematical formula and math.pow() function.
- Store it in another variable.
- Calculate the volume of the given hemisphere using the above given mathematical formula and math.pow() function.
- Store it in another variable.
- Print the hemisphere’s surface area with the given radius of the hemisphere.
- Print the hemisphere’s perimeter with the given radius of the hemisphere.
- The Exit of the program.
Below is the implementation:
# Import the math module using the import keyword. import math # Give the hemisphere's radius as user input using the float(input()) function and # store it in a variable. gvn_radus = float(input("Enter some random variable = ")) # Take a variable and initialize it with the value of pi as 3.14 . valof_pi = 3.14 # Calculate the surface area of the given hemisphere using the above given mathematical # formula and math.pow() function. # Store it in another variable. hemi_surfceara = 3*valof_pi*math.pow(gvn_radus, 2) # Calculate the volume of the given hemisphere using the above given mathematical formula # and math.pow() function. # Store it in another variable. hemi_volum = (2.0/3.0)*valof_pi*math.pow(gvn_radus, 3) # Print the hemisphere's surface area with the given radius of the hemisphere. print("The Surface Area of the given Hemisphere with radius {", gvn_radus, " } = ", hemi_surfceara) # Print the hemisphere's perimeter with the given radius of the hemisphere. print("The Volume of the given Hemisphere with radius {", gvn_radus, "} = ", hemi_volum)
Output:
Enter some random variable = 12.5 The Surface Area of the given Hemisphere with radius { 12.5 } = 1471.875 The Volume of the given Hemisphere with radius { 12.5 } = 4088.5416666666665