Programming Examples

Python program to calculate volume of cuboid cylinder and cone based on user choice


The volume of solids viz. cuboid, cylinder and cone can be calculated by the following formulae:

1. Volume of a cuboid (V= 1*b*h)

2. Volume of a cylinder (V=*π*r2*h)

3. Volume of a cone (V=1/3*π*r2h) [π= 22/7 ]

Write a Python code by using user’s choice to perform the above task.

Solution:

print("1. Volume of Cuboid");
print("2. Volume of Cylinder");
print("3. Volume of Cone");
c=int(input("Enter your choice: "))
if(c==1):
	print("Enter three sides of a cuboid:")
	I= float(input("Enter length: "))
	b=float(input("Enter breath: "))
	h=float(input("Enter height: "))
	vol= l*b*h
	print("Volume of Cuboid =",vol)
elif(c==2):
	print("Enter radius and height of a cylinder")
	r=float(input("Enter radius: "))
	h=float(input("Enter height: "))
	vol=(22*r*r*h)/7
	print("Volume of Cylinder =",vol);
elif(c==3):
	print("Enter radius and height of a cone")
	r= float(input("Enter radius: "))
	h= float(input("Enter height: " ))
	vol=(22*r*r*h)/(3*7)
	print("Volume of cone =",vol);
else:
	print("Wrong Choice!!")

Output

1. Volume of Cuboid

2. Volume of Cylinder

3. Volume of Cone

Enter your choice: 2

Enter radius and height of a cylinder

Enter radius: 5.6

Enter height: 9

Volume of Cylinder = 887.0399999999998

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad