
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Calculate the Area of a Triangle using Python
Calculating the area of a triangle is a formula that you can easily implement in python. If you have the base and height of the triangle, you can use the following code to get the area of the triangle,
def get_area(base, height): return 0.5 * base * height print(get_area(10, 15))
This will give the output:
75
If you have the sides of the triangle, you can use herons formula to get the area. For example,
def get_area(a, b, c): s = (a+b+c)/2 return (s*(s-a)*(s-b)*(s-c)) ** 0.5 print(get_area(10, 15, 10))
This will give the output:
49.607837082461074
Advertisements