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

Remove Ads
Teachoo · Class 12 Explore Class 12

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 is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.