Page 66 - PYTHON-11
P. 66
Ans. import math
while True:
print("\nMenu:")
print("1. Calculate Area of Rectangle")
print("2. Calculate Perimeter of Rectangle")
print("3. Calculate Area of Circle")
print("4. Calculate Circumference of Circle")
print("5. Calculate Area of Triangle")
choice = int(input("Enter your choice (1-5): "))
if choice == 1:
length = float(input("Enter the length of the rectangle: "))
breadth = float(input("Enter the breadth of the rectangle: "))
rect_area = length * breadth
print("Area of the rectangle is:", rect_area)
elif choice == 2:
length = float(input("Enter the length of the rectangle: "))
breadth = float(input("Enter the breadth of the rectangle: "))
perimeter = 2 * (length + breadth)
print("Perimeter of the rectangle is:", perimeter)
elif choice == 3:
radius = float(input("Enter the radius of the circle: "))
cir_area = math.pi * radius ** 2
print("Area of the circle is:", cir_area)
elif choice == 4:
radius = float(input("Enter the radius of the circle: "))
circumference = 2 * math.pi * radius
print("Circumference of the circle is:", circumference)
elif choice == 5:
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
tri_area = 0.5 * base * height
print("Area of the triangle is:", tri_area)
else:
print("Invalid choice! Please enter a number between 1 and 5.")
M.15