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/ Explanation:

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

Latest Current Affairs 2025 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad