Check sibling questions

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

Are ads bothering you?


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’

CA Maninder Singh's photo - Expert in Practical Accounts, Taxation and Efiling

Made by

CA Maninder Singh

CA Maninder Singh is a Chartered Accountant for the past 12 years. He also provides Accounts Tax GST Training in Delhi, Kerala and online.