YouTip LogoYouTip

Python3 Area Triangle

# Python3.x Python Calculate Triangle Area [![Image 3: Document Object Reference](#) Python3 Examples](#) The following example calculates the area of a triangle by taking the lengths of its three sides as input from the user: ## Example (Python 3.0+) # -*- coding: UTF-8 -*-# Filename : test.py# author by : www..com a = float(input('Enter the length of the first side of the triangle: '))b = float(input('Enter the length of the second side of the triangle: '))c = float(input('Enter the length of the third side of the triangle: '))# Calculate semi-perimeter s = (a + b + c) / 2# Calculate area area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 print('The area of the triangle is %0.2f' %area) Executing the above code produces the following output: $ python test.py Enter the length of the first side of the triangle: 5Enter the length of the second side of the triangle: 6Enter the length of the third side of the triangle: 7The area of the triangle is 14.70 [![Image 4: Document Object Reference](#) Python3 Examples](#)
← Python3 Celsius FahrenheitPython3 99 Table β†’