Python Program to Calculate the Area of a Triangle

Python Programming Examples


This Python example code demonstrates a simple Python program to calculate the area of a triangle and print the output to the screen.

Program:

a = 20
b = 16
c = 30

#Remove comments from the bottom lines to take input from the user
#a = float(input('Enter the first side: '))
#b = float(input('Enter the second side: '))
#c = float(input('Enter the third side: '))

#Semi-perimeter calculation
s = (a + b + c) / 2

#Area calculation
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5

#Print the output
print('The area of the triangle is %0.2f' %area)

Program Output:

The area of the triangle is 147.92


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram

Notifications

Updates are enabled for this browser.

Receive new tutorials, articles and learning resources. You can turn updates off anytime.

Test browser code

Use this code in admin to send a test notification to this browser.