Python Program to Calculate the Area of a Triangle

Spread the love

In this tutorial, You will learn how to write python program to calculate the areĀ  of a triangle.

Formula :

area=sqrt(s(s-a)(s-b)(s-c)/2)

#Python Program to Calculate the Area of a Triangle program

In this program we are using using python inbuilt function sqrt function from math library.

import math

a=8

b=4

c=6

# to calculate the semi parameter

s=(a+b+c)/2

area = math.sqrt(s*(s-a)*(s-b)*(s-c))

print("Area of triangle",area)

Output:

Area of triangle 11.61895003862225
#Python Program to Calculate the Area of a Triangle program from dynamic variables.
We are using python input() function to get dynamic values. These values stores in a, b, c variables.
import math

a=float(input("enter side value of triangle "))

b=float(input("enter side value of triangle "))

c=float(input("enter side value of triangle "))

# to calculate the semi parameter

s=(a+b+c)/2

area = math.sqrt(s*(s-a)*(s-b)*(s-c))

print("Area of triangle is ",area)

Output:

enter side value of triangle 5
enter side value of triangle 10
enter side value of triangle 10
Area of triangle is 24.206145913796355

 

admin

admin

Leave a Reply

Your email address will not be published. Required fields are marked *