Measuring Area & Volume using Python

Create Area & Volume Measuring Program Using Python

We have all calculated the area and volume of different geometrical shapes in the lower class. It is also useful in Arithmetic, Physics and Chemistry Field. While studying, We memorized many mathematical formulas related to Area & Volume of different shapes. But many times there were problems in calculation. Even if the formula is applied correctly, the whole answer would be wrong for the mistake in calculation.

Math Module Measuring Area & Volume of Different Shapes, Python Program to find Volume & Surface Area of a Cylinder, Python Program to find volume, surface area and space diagonal of a cuboid, Python Program to find Volume and Surface Area of a Cube, calculate the area and volume of different shapes using python
Area & Volume Measuring Program Using Python

Something it gives a math problem whose calculation becomes too big and it is more likely to be wrong. It must have occurred to you that if you had a calculator like Google, I would just give the value as a input and it would automatically calculate and answer the problem without writing any formulas.
Is that possible? Is it possible to make such a calculator? Even if it can be made, how can i make it?
All these questions will come to mind.

Now I would say yes friends... it is possible to make such a calculator or tool which will take the value from you as input and tell you the area and volume of different geometrical shapes without writing any formula.

So let's see how to make this calculator. One more thing before that if you are a computer student or if you are a beginner of programming and have just started learning python then you can see this blog as a python exercise. You can go to the home page of this website and read more programming related blog & contents and see it and practice it yourself.

Also I provide the full source code in this blog. In this we have to take the help of a module called Math Module but you can make this calculator in addition to this  Math Module.

I will build this measuring calculator in version 3.9.7 of python and I will use pycharm as text editor.
Download Python: link
Download Pycharm: link
Quora Follow link: link

Source Code

import math # This is a  imported module
print("Welcome to Rajtech99 only technology!\n")
print("This is the Area & Volume Measuring tool\n")

while(1):
print("Input 1 for Area Measurement\n"
"Input 2 for Volume Measurement\n"
"Input 00 for Exit!!\n")
inp1 = int(input("Input Here: "))
if inp1 == 1:
inp2 = int(input("Enter 1 for Circle\n"
"Enter 2 for Triangle\n"
"Enter 3 for Sphere\n"
"Enter 4 for Square\n"
"Enter 5 for Rectangle\n"
"Enter 6 for Ellipse\n"
"Enter 7 for Cone\n"
"Enter 8 for Cylinder\n"
"Enter 9 for Cube\n"
"Enter 10 for Trapezoid\n"
"Input 00 for Exit!!\n"
"Enter Here: "))
if inp2 == 1:
print("You select Circle")
R = float(input("Radius: "))
print("The required Area of the Circle: ", math.pi*R**2)
elif inp2 == 2:
print("You select Triangle")
B = float(input("Base: "))
H = float(input("Perpendicular Height: "))
print("The required Area of the Triangle: ", 1/2*B*H)
elif inp2 == 3:
print("You select Sphere")
R = float(input("Radius: "))
print("The required Area of the Sphere: ", 4*math.pi*R**2)
elif inp2 == 4:
print("You select Square")
A = float(input("Side lenght: "))
print("The required Area of the Square: ", A**2)
elif inp2 == 5:
print("You select Rectangle")
L = float(input("Lenght: "))
W = float(input("Width: "))
print("The required Area of the Rectangle: ", L*W)
elif inp2 == 6:
print("You select Ellipse")
x = float(input("Axis: "))
y = float(input("Axis: "))
print("The required Area of the Ellipse: ", math.pi*x*y)
elif inp2 == 7:
print("You select Cone")
R = float(input("Radius: "))
H = float(input("Height: "))
print("The required Area of the Cone: ",
(math.pi*R*R)+(math.pi*R*(H**2+R**2)**(1/2)))
elif inp2 == 8:
print("You select Cylinder")
r = float(input("Radius: "))
h = float(input("Height: "))
print("The required Area of the Cylinder: ", 2*math.pi*r*(h+r))
elif inp2 == 9:
print("You select Cube")
A = float(input("Edge: "))
print("The required Area of the Cube: ", 6*A*A)
elif inp2 == 10:
print("You select Trapezoid in 2D Shape")
B = float(input("Base 1: "))
b = float(input("Base 2: "))
h = float(input("Height: "))
print("The required Area of the Trapezoid in 2D Shape: ", h*(B/2+b/2))
elif inp2 == 00:
print("Exit!!")
break
else:
print("Enter correct Input!!")
break
elif inp1 == 2:
inp2 = int(input("Enter 1 for Triangle\n"
"Enter 2 for Sphere\n"
"Enter 3 for Square\n"
"Enter 4 for Rectangle\n"
"Enter 5 for Ellipse\n"
"Enter 6 for Cone\n"
"Enter 7 for Cylinder\n"
"Enter 8 for Cube\n"
"Enter 9 for Trapezoid\n"
"Input 00 for Exit!!\n"
"Enter Here: "))
if inp2 == 1:
print("You select Triangle")
B = float(input("Base: "))
H = float(input("Perpendicular Height: "))
L = float(input("Lenght: "))
print("The required Volume of the Triangle: ", 1/2*B*H*L)
elif inp2 == 2:
print("You select Sphere")
R = float(input("Radius: "))
print("The required Volume of the Sphere: ", 4/3*math.pi*R**3)
elif inp2 == 3:
print("You select Square")
A = float(input("Side lenght: "))
print("The required Volume of the Square: ", A**3)
elif inp2 == 4:
print("You select Rectangle")
L = float(input("Lenght: "))
W = float(input("Width: "))
H = float(input("Height: "))
print("The required Volume of the Rectangle: ", L*W*H)
elif inp2 == 5:
print("You select Ellipse")
x = float(input("Axis: "))
y = float(input("Axis: "))
z = float(input("Axis: "))
print("The required Volume of the Ellipse: ", 4/3*math.pi*x*y*z)
elif inp2 == 6:
print("You select Cone")
R = float(input("Radius: "))
H = float(input("Height: "))
print("The required Volume of the Cone: ", math.pi*R**2*H/3)
elif inp2 == 7:
print("You select Cylinder")
r = float(input("Radius: "))
h = float(input("Height: "))
print("The required Volume of the Cylinder: ", math.pi*r**2*h)
elif inp2 == 8:
print("You select Cube")
A = float(input("Edge: "))
print("The required Volume of the Cube: ", A**3)
elif inp2 == 9:
print("You select Trapezoid in 2D Shape")
l = float(input("Lenght: "))
b = float(input("Base Width: "))
h = float(input("Height: "))
t = float(input("Top Width: "))
print("The required Volume of the Trapezoid in 2D Shape: ", l*h*(b+t)/2)
elif inp2 == 00:
print("Exit!!")
break
else:
print("Enter correct Input!!")
break
elif inp1 == 00:
print("Exit!!")
break

Conclusion

With this program you can determine the area and volume of different shapes. You can add more codes for more shapes as per your requirement. You can easily finish many complex calculations using it alone. It will save your time also. There is no complication in this program. Simple while loop and if, elif & else statements have been used.
I hope you like this blog and you can also follow my Quora Space for free. Here I write Tech related short posts.
After that you can find out in the comments what kind of blog you want to read or watch.
Thanks for read this blog!!
Raj Manna

My name is Raj. I am a student of 1st year physics honorus.

1 Comments

If you have any doubts, Please let me know

Post a Comment
Previous Post Next Post