import math as m def square(): side = int(input("Enter a edge for square: ")) diagonal = m.sqrt(2*(side**2)) perimeter = 4*side area = side**2 print(""" SIDE : {} PERIMETER : {} DIAGONAL : {} AREA : {} """.format(side,perimeter,diagonal,area)) def distance(): print("You need to enter two point (x1,y1) and (x2,y2)") x1 = int(input("X1 :")) y1 = int(input("Y1 :")) x2 = int(input("X2 :")) y2 = int(input("Y2 :")) distance = m.sqrt(((x2-x1)**2)+((y2-y1)**2)) print(""" Distance between ({},{}) and ({},{}) = {} """.format(x1,y1,x2,y2,distance)) def right_triangle(): hipo = int(input("Enter a hypotenuse: ")) perp = int(input("Enter perpendicular edge: ")) other = int(input("Enter other edge: ")) flag = hipo**2 == perp**2+other**2 if flag: area = (perp*other) / 2 print(""" AREA : {} """.format(area)) else: print(""" This is not a right triangle, Try Again!!!! """) def circle(): radius = int(input("Enter the radius for circle: ")) circumference = 2*radius*m.pi area = m.pi*(radius**2) diameter = 2*radius print(""" RADIUS : {} CIRCUMFERENCE : {} AREA : {} DIAMETER : {} """.format(radius, circumference, area, diameter)) def rectangle(): lside = int(input("Enter a long edge for rectangle: ")) sside = int(input("Enter a short edge for rectangle: ")) perimeter = 2*(lside+sside) area = lside*sside print(""" EDGES : {},{} PERIMETER : {} AREA : {} """.format(lside,sside,perimeter,area)) def menu(): print(""" Welcome, please select one operation... [1] SQUARE [2] DISTANCE OF TWO POINTS [3] RIGHT TRIANGLE [4] CIRCLE [5] RECTANGLE [0] EXIT """) ch = int(input()) return ch def menu2(): print(""" Would you like to take another operation? [1] YES [0] EXIT """) ch = int(input()) return ch flag = True while flag: choose = menu() if choose == 1: square() elif choose == 2: distance() elif choose == 3: right_triangle() elif choose == 4: circle() elif choose == 5: rectangle elif choose == 0: print("You exit successfully...") flag = False