To calculate area of a triangle in python, you have to ask from user to enter length of first, second, and third side to calculate and print area of that triangle on the output screen as shown in the program given below.
Following python program ask from user to enter length of all the three sides and then calculate and print the area of triangle:
# Python Program - Calculate Area of Triangle print("Enter 'x' for exit."); side1 = input("Enter length of first side: "); if side1 == 'x': exit(); else: side2 = input("Enter length of second side: "); side3 = input("Enter length of third side: "); a = float(side1); b = float(side2); c = float(side3); s = (a + b + c)/2; area = (s*(s-a)*(s-b)*(s-c)) ** 0.5; print("\nArea of Triangle = %0.2f" %area);
Here is the sample run of the above Python program shows how to calculate area of a triangle:
Now enter length of all the three sides of triangle, that is length, breadth, and height say 10, 11, and 12 respectively and then press enter to see the area of this triangle as shown in the following sample output:
Below is the same program with run on python shell:
Program Video with Compile and Run