Menu driven python program to find volume of different shapes
In this exercise, we will be creating a menu driven python program to find volume of different shapes like cylinder, cone, hemisphere, cube, cuboid,etc.
In this, we first create a menu and we ask the user to input some number according to the shape he want to find the volume. Then, we take the neccessary parameters of the shape for example if we want to find the volume of cube then we take the length of it's side for sphere we take it's radius and for cylinder we take it's height and radius.
I hope the question would be clear to you. You are advised to try it first and then check the program source code which is given below.
You can run and code in python online on this website - Python Online Interpreter
print("What is the shape of container whose volume you want to find")print ("Enter 1 for Cylinder, 2 for Cone, 3 for Sphere/Hemisphere, 4 for cube, 5 for cuboid")O = input ("Enter codes from above data as per your requirement" )if O > '0' and O <= '5':if O == '1':r= float(input ("Enter radius"))h= float(input ("Enter height"))V= 3.14*r**2*hprint ("Volume=", V)elif O == '2':r= float(input ("Enter radius"))h= float(input ("Enter height"))V= (3.14*r**2*h)/3print ("Volume=", V)elif O == '3':r= float(input ("Enter radius"))V=(4*3.14*r**3)/3v=(2*3.14*r**3)/3print ("Volume of Sphere=", V)print ("Volume of Hemisphere=", v)elif O == '4':a= float(input ("Enter length of side"))V= a**3print ("Volume=", V)elif O == '5':l= float(input ("Enter length"))b= float(input ("Enter breadth"))h= float(input ("Enter height"))V=l*b*hprint ("Volume=", V)print ("I hope this program has helped you somehow")print ("Thank you for using this program")else:print ("Invalid Code\a")print ("Use the valid codes from above line")
Output
What is the shape of container whose volume you want to find
Enter 1 for Cylinder, 2 for Cone, 3 for Sphere/Hemisphere, 4 for cube, 5 for cuboid
Enter codes from above data as per your requirement4
Enter length of side10
Volume= 1000.0
I hope this program has helped you somehow
Thank you for using this program
Post a Comment
For any doubts feel free to ask in comments below.
Stay Connected to Us for more such Courses and Projects.