Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Math toolbox You are write a Python program that will be your math tool box, it

ID: 3711015 • Letter: M

Question

Math toolbox You are write a Python program that will be your math tool box, it should have at least the following functions: where you have the following functions to calculate area and circumference of four geometrical shapes namely: • Square o ( Area = Length * length , Cir= 4* Length) • Rectangle o ( Area = Length * width , Cir= 2* (Length + Width)) • Triangle o (Area= 0.5* base * height, Circ= side1+ side2+side3) • Circle o (Area = Pi*Radius*Radius, Cir= 2*Pi*Radius) Program will print a menu so that the user will select one of the following options: Option 1: Exit the program Option 2: Shape = Square Option 3: Shape= Rectangle Option 4: Shape= Circle Option 5: Shape= Triangle Then for each shape you will ask user to input needed data (for example for a rectangle you need Length and Width) to calculate area and circumference

Explanation / Answer

#function for square
def square(length):
area=float(length*length)
cir=float(4*length)
print("area="+str(area))
print("perimeter="+str(cir))

#function for rectangle
def rectangle(length,width):
area=float(length*width)
cir=float(2*(length+width))
print("area=" + str(area))
print("perimeter=" + str(cir))

#function for triangle
def triangle(side1,side2,side3,base,height):
area=float(0.5*base*height)
cir=float(side1+side2+side3)
print("area=" + str(area))
print("perimeter=" + str(cir))

#function for circle
def circle(radius):
area=float(3.14*radius*radius)
cir=float(2*3.14*radius)
print("area=" + str(area))
print("perimeter=" + str(cir))

#Menu for user
print("1.Exit the program")
print("2.Shape=square")
print("3.Shape=rectangle")
print("4.Shape=triangle")
print("5.Shape=circle")

#input by user
option=input(" Choose an option ")

#to exit the program
if option=="1":
print("Exited")

#for square
elif option=="2":
length=float(input("Enter the side length for square="))

#calling function square
square(length)

#for rectangle
elif option=="3":
length=float(input("Enter the length of rectangle="))
width=float(input("Enter the width of rectangle="))

#calling function rectangle
rectangle(length,width)

#for triangle
elif option=="4":
side1=float(input("Enter the side1 of triangle="))
side2 = float(input("Enter the side2 of triangle="))
side3 = float(input("Enter the side3 of triangle="))
base = float(input("Enter the height of triangle="))
height = float(input("Enter the base of triangle="))

#calling function triangle
triangle(side1,side2,side3,base,height)

#for circle
elif option=="5":
radius=float(input("Enter the radius of circle="))

#calling function circle
circle(radius)

#for invalid selection
else:
print("You have made an invalid choice")