Sep-25-2017, 06:45 PM
First of all I need to verify if I can draw a triangle, is_valid(s1,s2,s3): is giving correct answers.
Then, I have to find the area of the triangle, the answers are also correct.
Finally, when I have to find if the triangle is valid AND find the area of the triangle, it's giving me correct answers for if the triangle is valid, and giving me a ValueError: math domain something for when the values give me an invalid triangle.
Help?
Then, I have to find the area of the triangle, the answers are also correct.
Finally, when I have to find if the triangle is valid AND find the area of the triangle, it's giving me correct answers for if the triangle is valid, and giving me a ValueError: math domain something for when the values give me an invalid triangle.
Help?
import sys
import math
s1 = float(sys.argv[1])
s2 = float(sys.argv[2])
s3 = float(sys.argv[3])
def is_valid(s1, s2, s3):
lf=[float(s1), float(s2), float(s3)]
for flt in lf:
if s1 + s2 > s3 and s1 + s3 > s2 and s2 + s3 > s1:
return True
else:
return False
print(is_valid(s1, s2, s3))
def area(s1, s2, s3):
s=(s1 + s2 + s3)/2
ar=math.sqrt(s*(s-s1)*(s-s2)*(s-s3))
return ar
print(area(s1, s2, s3))
if is_valid(s1, s2, s3) == True:
print('Valid Triangle:', end='')
print(area(s1, s2, s3))
else:
print('Invalid Triangle')
