Python Program to find the area of Triangle

0
314
Program to find the Python area of Triangle

In this program, you’ll learn how to find the area of a Triangle in Python

To properly understand this example to find the area of a triangle in Python, you should have the knowledge of following Python programming topics:

  1. Input, Output, and Import
  2. Variables and Data Type
  3. Operators

The Area of a triangle is equal to half of the product of its base and height.

The height of a triangle is the perpendicular distance from a vertex to the base of the triangle.

(Note: 12 is the height, not the length of the left-hand side)

Base = b = 20

Area = ½ bh = ½ × 20 × 12 = 120

#for semi perimeter
s = (a+b+c)/2

# for area
area = √(s(s-a)*(s-b)*(s-c))

Program to find the Area of a Triangle

a = 5
b = 6
c = 7

# Uncomment below to take inputs from the user
# a = float(input('Enter first side: '))
# b = float(input('Enter second side: '))
# c = float(input('Enter third side: '))

# calculate the semi-perimeter
s = (a + b + c) / 2

# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area)

Output:

The area of the triangle is 14.70

here if ab, and c are three sides of the triangle so this can be solved by the mathematical formula

Python Program to find the area of a Triangle

In this program, the area of the triangle is calculated when three sides are given using Heron’s formula.

If you need to calculate the area of a triangle depending upon the input from the user, input() function can be used. or can refer to the previous program Program to find the Addition of Two Numbers Given by User in Python.

Related Programs

  1. Python Program to Solve Quadratic Equation.
  2. Python Program to Generate a Random Number.
  3. Python Program to Generate a Random alphanumeric String.
  4. Python Program to find the Square Roots
  5. Python Program to Shuffle Deck of Cards
  6. Python program convert decimal number to binary number using recursion
  7. Python Program to Find Factorial of a Number Using Recursion
  8. Python Program to Check if a Number is Positive, Negative or 0
  9. Python Program to Display Fibonacci Sequence Using Recursion
  10. Python Program to Find Factorial of a Number Using Recursion

Ask your questions and clarify your/other doubts on the Program to find the area of a triangle in Python by commenting. Python Documentation