Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions Areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: "))
Expand All @@ -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}")
print(f"The area of the shape is: {final_area}")