Python program to calculate the area of a parallelogram
In this tutorial, we are going to learn how can we calculate the area of the parallelogram in the Python programming language.
The parallelogram is a geometrical figure of a four-sided plane with opposite sides parallel. A parallelogram is a simple object in 2D space that has two parallel sides. The opposite sides and the angles are identical in a parallelogram.
Formula to calculate the parallelogram area:
Area = base * height where base is the parallel sides and height is distance between the parallel sides
Step by step approach to calculating the area is given below:
define the base of the parallelogram. define the height of the parallelogram. calculate the area of the parallelogram using the above formula The time complexity will beĀ O(1).
Now let’s move on our real Python program to do this task:
First of all, let’s take the base as an input from the user:
#parellel sides of the parallelogram: Base = float(input('Enter the Base of a parallelogram: '))
Now take the height as an input from the user:
#distance between two parelle sides Height = float(input('Enter the Height of a parallelogram: '))
After that, let’s calculate the area of the parallelogram using the formula that we learned in mathematics when we were in school:
# calculate the area of parallelogram area=Base*Height
Now printing the output value using the Python print function to display the result of the calculation:
print("The area of the parallelogram=",area)
Now combine the whole Python program:
#parellel sides of the parallelogram: Base = float(input('Enter the Base of a parallelogram: ')) #distance between two parelle sides Height = float(input('Enter the Height of a parallelogram: ')) # calculate the area of parallelogram area=Base*Height print("The area of the parallelogram=",area)
Output:
Enter the Base of a parallelogram: 6 Enter the Height of a parallelogram: 5 The area of the parallelogram= 30.0
Also, read:
Leave a Reply