From 7e28113fe4abe52bd59cac6fa8682c4855c6b10e Mon Sep 17 00:00:00 2001 From: Adhi Agrawal Date: Sun, 23 Aug 2026 10:45:11 +0530 Subject: [PATCH] Fix invalid triangle side validation Added validation for triangle sides and adjusted input handling. --- Areas.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/Areas.py b/Areas.py index 80518366..39e8b047 100644 --- a/Areas.py +++ b/Areas.py @@ -11,10 +11,14 @@ def rectangle(length, breadth): return area def triangle(side1, side2, side3): + if side1 + side2 <= side3 or side1 + side3 <= side2 or side2 + side3 <= side1: + print("Invalid triangle sides.") + return None + s = (side1 + side2 + side3)/2 area = math.sqrt(s*(s-side1)*(s-side2)*(s-side3)) return area - + def circle(radius): area = 3.14 * radius * radius return area @@ -38,12 +42,15 @@ def circle(radius): final_area = rectangle(length, breadth) break - elif shape.lower() == "triangle": - side1 = float(input("Enter the value of 1st side: ")) - side2 = float(input("Enter the value of 2nd side: ")) - side3 = float(input("Enter the value of 3rd side: ")) - final_area = triangle(side1, side2, side3) - break + elif shape.lower() == "triangle": + side1 = float(input("Enter the value of 1st side: ")) + side2 = float(input("Enter the value of 2nd side: ")) + side3 = float(input("Enter the value of 3rd side: ")) + final_area = triangle(side1, side2, side3) + + if final_area is None: + continue + break elif shape.lower() == "circle": radius = float(input("Enter the value of radius: ")) @@ -53,4 +60,4 @@ def circle(radius): else: print("Please choose a shape from the given 4 or check your spelling again") -print(f"The area of the shape is: {final_area}") \ No newline at end of file +print(f"The area of the shape is: {final_area}")