Python Program to Calculate Area of Triangle

After this tutorial, you will be able to write a Python program to calculate the area of the triangle.

If you are new to Python programming, you should first read these topics to have a better understanding of this code:

Now let’s take a look at the code (I have an explained version of the same code down below).

Simple Code

print('To calculate the area of a triangle')
base = float(input('Enter its base: '))
height = float(input('Enter its height : '))
area = 1 / 2 * ( base * height )
print('The area of the triangle is' , area)

Output

To calculate the area of a triangle
Enter its base: 12
Enter its height : 12
The area of the triangle is 72.0

Explained: Python Program to find the area of a triangle

print('To calculate the area of a triangle')
#take input from user, and then convert it into float. This input is stored in base variable
base = float(input('Enter its base: '))
#take input from user, and then convert it into float. This input is stored in height variable
height = float(input('Enter its height : '))
#this is the formula to find the area of a triangle
#after calculating the area, it is stored in the area variable
area = 1 / 2 * ( base * height )
#finally the output is printed on the output screen
print('The area of the triangle is' , area)
Was this helpful?
YesNo

Related Articles:

Recent Articles:

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x