def my_circle():
π = 3.14
r = float(input("Enter circle radius in cm: "))
A = (π*r*r)
P = ((π*r)*2)
print("area of circle is:", A , " cm^2")
print("Perimeter of circle is:", P , " cm")
def my_square():
l = float(input("Enter square length in CM: "))
A = (l*l)
P= (l*4)
print("area of square is:", A , " cm^2")
print("Perimeter of square is:" , P , " cm")
def my_rectangle():
l = float(input("Enter rect. length in CM: "))
w = float(input("Enter rect. width in cm: "))
A = (l*w)
P= ((l+w)*2)
print("area of rectangle is:", A , " cm^2")
print("Perimeter of rectangle is:" , P , " cm")
def my_triangle():
h = float(input("Enter height in CM: "))
b = float(input("Enter base in cm: "))
A = ((b/2)*h)
print("area of triangle is:", A , " cm^2")
while True:
print (" /////**** Wekcome to area and perimeter
calculator ****//////")
print ( " 1. square")
print ( " 2. rectangle")
print ( " 3. circle")
print ( " 4. triangle")
print ( " 5. Exit")
print ( )
A=int(input ("choose the 2D shape: " ) )
if A == 1:
my_square()
print ("End")
elif A == 2:
my_rectangle()
print ("End")
elif A ==3:
my_circle()
print ("End")
elif A == 4:
my_triangle()
print ("End")
elif A == 5:
break
else:
print (" Choose a proper selection")

Geometric calculator with python language

  • 1.
    def my_circle(): π =3.14 r = float(input("Enter circle radius in cm: ")) A = (π*r*r) P = ((π*r)*2) print("area of circle is:", A , " cm^2") print("Perimeter of circle is:", P , " cm") def my_square(): l = float(input("Enter square length in CM: ")) A = (l*l) P= (l*4) print("area of square is:", A , " cm^2") print("Perimeter of square is:" , P , " cm")
  • 2.
    def my_rectangle(): l =float(input("Enter rect. length in CM: ")) w = float(input("Enter rect. width in cm: ")) A = (l*w) P= ((l+w)*2) print("area of rectangle is:", A , " cm^2") print("Perimeter of rectangle is:" , P , " cm") def my_triangle(): h = float(input("Enter height in CM: ")) b = float(input("Enter base in cm: ")) A = ((b/2)*h) print("area of triangle is:", A , " cm^2")
  • 3.
    while True: print ("/////**** Wekcome to area and perimeter calculator ****//////") print ( " 1. square") print ( " 2. rectangle")
  • 4.
    print ( "3. circle") print ( " 4. triangle") print ( " 5. Exit") print ( ) A=int(input ("choose the 2D shape: " ) ) if A == 1: my_square()
  • 5.
    print ("End") elif A== 2: my_rectangle() print ("End") elif A ==3: my_circle() print ("End")
  • 6.
    elif A ==4: my_triangle() print ("End") elif A == 5: break else: print (" Choose a proper selection")