Home » Blog » Find The Area Of Triangle With Command Line Argument

Find The Area Of Triangle With Command Line Argument

Hello Guys,

This python program will calculate the area of equilibrium triangle. It takes the value of three sides from command line and check the third side of triangle has value greater than the sum of other two side and then calculate area for that. If the value of sides are not well then it gives error message.

import sys
import math

def areaTriangle (values):
    i=1
    j=2
    print("File Name : ",values[0])
    #print(values[1],values[2],values[3])
    s=(int(values[1])+int(values[2])+int(values[3]))/2
    print(s)
    area=math.sqrt(s * (s-int(values[1])) * (s-int(values[2])) * (s-int(values[3])))
    print("Area Of Triangle Of Three Side ",area)
        
        
values=sys.argv
if (len(values)<=1):
    print("Don't Have Any Argument")
else:
    if ((values[1]+values[2])<values[3] or (values[2]+values[3])<values[1] or (values[1]+values[2])<values[3]):
        print("*** Invalid Sum Of Two Side Is Less Than Third Side ***")
    else:
        areaTriangle(values)

 

Leave a Reply

Your email address will not be published.