Write a Python program using functions to calculate area of a triangle after obtaining its three sides.

 

Answer:

import math

 

def triangle_area (a,b,c):

    s=(a+b+c)/ 2

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

    return ar

 

a=float(input( "Enter first side of the triangle: " ))

b=float(input( "Enter second side of the triangle: " ))

c=float(input( "Enter third side of the triangle: " ))

 

area=triangle_area(a,b,c)

 

print("The area of a triangle with sides ",a,", ",b,", ",c," is ",area)

Question 7-Write a Python program - Teachoo.JPG

Go Ad-free

Transcript

Question 7 Write a Python program using functions to calculate area of a triangle after obtaining its three sides. Importing the ‘math’ library Calculating the area using heron’s formula and assigning the answer to the variable ‘ar’ Accepting user inputs for three sides of a triangle and assigning it to variables output defining a function ‘triangle_area’ to calculate the area Invoking function ‘triangle_area’ and assigning the value returned to the variable ‘area’

Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo