Write a program to find the area of a triangle, given its length of each side as 3, 5, 6.
时间: 2024-05-10 17:14:13 浏览: 81
Sure, here is a Python program to find the area of a triangle with sides of length 3, 5, and 6:
```python
# import math module for square root function
import math
# define the lengths of the sides of the triangle
a = 3
b = 5
c = 6
# calculate the semi-perimeter of the triangle
s = (a + b + c) / 2
# calculate the area of the triangle using Heron's formula
area = math.sqrt(s * (s - a) * (s - b) * (s - c))
# print the result
print("The area of the triangle is:", area)
```
This program first imports the `math` module to use the `sqrt` function. Then it defines the lengths of the sides of the triangle as variables `a`, `b`, and `c`. The program then calculates the semi-perimeter of the triangle, which is half of the sum of the lengths of the sides. Finally, it calculates the area of the triangle using Heron's formula, which involves taking the square root of a product of the semi-perimeter and the differences between the semi-perimeter and each side length. The program prints the result, which is the area of the triangle with sides of length 3, 5, and 6.
阅读全文