PYTHON

Ronak kumawat

Copy Editor
Blog Writer
SEO Writer
To find a triangle with the same area as a square in Python, you can use the following code:
```python
def area_of_triangle(base, height):
return 0.5 * base * height
def area_of_square(side):
return side * side
def find_triangle_with_same_area_as_square(side):
square_area = area_of_square(side)
base = side * 2
height = square_area / base
return base, height
side_length = float(input("Enter the side length of the square: "))
base, height = find_triangle_with_same_area_as_square(side_length)
triangle_area = area_of_triangle(base, height)
print("Base of triangle:", base)
print("Height of triangle:", height)
print("Area of triangle:", triangle_area)
print("Area of square:", area_of_square(side_length))
```
This code prompts the user to enter the side length of a square, calculates the base and height of a triangle with the same area as the square, and then calculates and displays the areas of both the triangle and the square.
Partner With Ronak
View Services

More Projects by Ronak