We can calculate the area of a triangle in python using Heron’s formula.
where s is the semi perimeter of the triangle that is calculated by the given formula:
s= (a+b+c)/2
and a, b and c are the lengths of three sides of the triangle.
We can calculate the area of a triangle in python using Heron’s formula.
where s is the semi perimeter of the triangle that is calculated by the given formula:
s= (a+b+c)/2
and a, b and c are the lengths of three sides of the triangle.
For example:
# area of a triangle using python
a = 5
b = 6
c = 7
# calculate the semi-perimeter
s = (a+b+c) /2
# calculate the area
area_tri = (s*(s-a)(s-b)(s-c)) ** 0.5
print('The area of triangle is : %0.2f' %area_tri)
Output:
The area of the triangle is 14.70
Related Questions
- How do you make a Triangle in Python?
- What does end =’ do in Python?
- What is Pascal Triangle in Python?
Related Topics
- Python Lambda (Anonymous) Function
- Python *args and **kwargs (With Examples)
- Python Array of Numeric Values
- Python Assert Statement
- Python Comments (With Examples)
- Python del Statement (With Examples)
- Python Dictionary Comprehension
- Python Functions (def): Definition with Examples
- Python Function Arguments (Default, Keyword and Arbitrary)
- Python Global Keyword (With Examples)
- Python Global, Local and Nonlocal variables (With Examples)
- Python ascii()
- Python delattr()
- Python super()
- Python locals()
- Python hash()
- Python id()
- Python sorted()
- Python dict()
- Python callable()
- Python dir()
- Python next()
- Python divmod()
- Python float()
- Python bytearray()
- Python filter()
- Python issubclass()
- Python __import__()
- Python enumerate()
- Python list()
- Python input()
- Python int()
- Python complex()
- Python zip()
- Python iter()
- Python bool()
- Python hex()
- Python open()
- Python ord()
- Python Built-in Functions
- Python oct()
- Python compile()
- Python reversed()
- Python tuple()
- Python frozenset()
- Python map()
- Python setattr()
- Python len()
- Python chr()
- Python object()
- Python bytes()
- Python getattr()
- Python slice()
- Python str()
- Python sum()
- Python isinstance()
- Python bin()
- Python type()
- Python range()
- Python Dictionary items()
- Python List sort()
- Python List reverse()
- Python String strip()
- Python String join()
- Python String split()
- Python User-defined Functions
Leave a Reply