In this activity, we will build an Area Calculator that can compute the area of three different shapes — a square, a rectangle, and a circle — based on the user's choice.
Shapes and Their Area Formulas



Area Formulas
Writing the Script
# Area Calculator import math print("Area Calculator") print("1. Square") print("2. Rectangle") print("3. Circle") choice = int(input("Choose a shape (1/2/3): ")) if choice == 1: side = float(input("Enter the side length: ")) area = side ** 2 print("Area of the square: " + str(area)) elif choice == 2: length = float(input("Enter the length: ")) width = float(input("Enter the width: ")) area = length * width print("Area of the rectangle: " + str(area)) elif choice == 3: radius = float(input("Enter the radius: ")) area = math.pi * radius ** 2 print("Area of the circle: " + str(round(area, 2))) else: print("Invalid choice. Please enter 1, 2, or 3.")
Understanding the Code
Code Breakdown
Testing the Program
- Run with choice = 1, side = 5 → Area should be 25.0
- Run with choice = 2, length = 6, width = 4 → Area should be 24.0
- Run with choice = 3, radius = 7 → Area should be approximately 153.94


.webp&w=3840&q=75)
.webp&w=3840&q=75)
.webp&w=3840&q=75)
.webp&w=3840&q=75)
.webp&w=3840&q=75)