DEV Community 👩‍💻👨‍💻

Mehammed Teshome
Mehammed Teshome

Posted on

Python programs to calculate perimetrs and areas of triangle, rectangle and circle.

Perimeters and areas of Triangle

the mathematical equation to calculate the perimeter and area of a Triangle with height(h), length(l) and width(w) is :
p= h+l+w
a=1/2(l*w)

so with python it can be executed as

length=float(input("Enter length : "))
width =float(input("Enter width : "))
height=float(input("Enter height: "))

print("the perimetre of the triangle is : " +str(length+width+height))
print("the area of the triangle is : " +str(1/2*(length*width)))
Enter fullscreen mode Exit fullscreen mode

and the output will be

Enter length : 2
Enter width : 3
Enter height: 4
the perimeter of the triangle is : 9.0
the area of the triangle is : 3.0

Perimeters and areas of rectangle

the mathematical equation to calculate the perimeter and area of a Rectangle with length(l) and width(w) is :
p= 2l + 2w
a= l*w
and the code will be

length=float(input("Enter length : "))
width =float(input("Enter width : "))

print("the perimeter of the rectangle is : "+str(2*length+2*width))
print("the area of the rectangle is : "+str(length*width))
Enter fullscreen mode Exit fullscreen mode

and the output will be

Enter length : 2
Enter width : 3
the perimeter of the rectangle is : 10.0
the area of the rectangle is: 6.0

Perimeters and areas of Circle

the mathematical equation to calculate the perimeter and area of a Circle with radius(r) is :
p= 2*PI*r
a=PI*r**2

so with python it can be executed as

from math import pi
r=float(input("Enter radius : "))
print("the Perimetre of the circle with radius "+str(r)+" is : " +str(2*pi*r))
print("the area of the circle with radius "+str(r)+" is : " +str(pi*r**2))
Enter fullscreen mode Exit fullscreen mode

and the output will be

Enter radius : 3
the Perimeter of the circle with radius 3.0 is : 18.84955592153876
the area of the circle with radius 3.0 is : 28.274333882308138

Top comments (0)

Timeless DEV post...

How to write a kickass README

Arguably the single most important piece of documentation for any open source project is the README. A good README not only informs people what the project does and who it is for but also how they use and contribute to it.

If you write a README without sufficient explanation of what your project does or how people can use it then it pretty much defeats the purpose of being open source as other developers are less likely to engage with or contribute towards it.