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 while True: print("Enter 'x' for exit.") side1 = input("Enter length of first side: ") side2 = input("Enter length of second side: ") side3 = input("Enter length of third side: ") if side1 == 'x': break else: 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("Area of Triangle = %0.2f" %area)
Here is the sample run of the above Python program shows how to calculate area of a triangle: