I'm a newbie to Python and I came across this question somewhere:
"Produce a programme that can calculate the perimeter of the triangle, the area of the triangle and the height of the triangle from the length of the three sides of a triangle. If the three lengths of the sides of the triangle do not define a valid triangle, a message should be displayed stating that this is not a valid calculation and the process should be terminated."
Anyone know how this could be solved? It's probably easy, but I'm a newbie so yeah
This is what I've got so far:
a = float(input('Please Enter the First side of a Triangle: '))
b = float(input('Please Enter the Second side of a Triangle: '))
c = float(input('Please Enter the Third side of a Triangle: '))
if a + b >= c and b + c >= a and c + a >= b:
# calculate area and height here
Perimeter = a + b + c
s = (a + b + c) / 2
Area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print("\n The Perimeter of Triangle = %.2f" %Perimeter);
print(" The Area of a Traiangle is %0.2f" %Area)
else:
print('Not a valid triangle')
I still have to calculate the height. Everything else seems to be working now :D