In: Computer Science
Write a design algorithm and a python program which asks the user for the length of the three sides of two triangles. It should compute the perimeter of the two triangles and display it. It should also display which triangle has the greater perimeter. If both have the same perimeter it should display that the perimeters are the same. Formula: Perimeter of triangleA = (side1A + side2A +side3A) See the 2 sample outputs. Enter side1 of TriangleA: 2 Enter side2 of TriangleA: 3 Enter side3 of TriangleA: 4 Enter side1 of TriangleB: 1 Enter side2 of TriangleB: 2 Enter side3 of TriangleB: 2 perimeter of TriangleA: 9.00 perimeter of of TriangleB: 5.00 perimeter of TriangleA is greater than perimeter of TriangleB. or Enter side1 of TriangleA: 2 Enter side2 of TriangleA: 1 Enter side3 of TriangleA: 3 Enter side1 of TriangleB: 1 Enter side2 of TriangleB: 2 Enter side3 of TriangleB: 3 perimeter of TriangleA: 6.00 perimeter of of TriangleB: 6.00 perimeter of TriangleA is equal to perimeter of TriangleB. PYTHON!!
Aside1 = float(input("Enter side1 of TriangleA:"))
Aside2 = float(input("Enter side2 of TriangleA:"))
Aside3 = float(input("Enter side3 of TriangleA:"))
Bside1 = float(input("Enter side1 of TriangleB:"))
Bside2 = float(input("Enter side2 of TriangleB:"))
Bside3 = float(input("Enter side3 of TriangleB:"))
Aperimeter = Aside1+Aside2+Aside3;
Bperimeter = Bside1 + Bside2+Bside3;
# .2f means how many digit after decimal .
print("perimeter of TriangleA:%.2f" %Aperimeter)
print("perimeter of TriangleB:%.2f" %Bperimeter)
if Aperimeter==Bperimeter:
print("perimeter of TriangleA is equal to perimeter of TriangleB.");
elif Aperimeter>Bperimeter:
print("perimeter of TriangleA is greater than perimeter of TriangleB.");
else:
print("perimeter of TriangleA is less than perimeter of TriangleB.");
In the code there are variables of sides of trangle A and B which is taking float values from the use and computing the result according to given in the quesiton.