Calculating Areas Of Different Shapes Using Python Last Updated : 07 Jun, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report We are going to make a Python program for Calculating Areas Of some mathematical Shapes. Example: Input: shape name = "Rectangle" length = 10 breadth = 15 Output: Area: 150 Input: shape name = "Square" side = 10 Output: Area: 100 Approach: In this program, We will ask the user to input the shape's name. If it exists in our program then we will proceed to find the entered shape's area according to their respective formulas. If that shape doesn't exist then we will print “Sorry! We cannot find this shape.” message on the screen. Below is the implementation: Python3 # define a function for calculating # the area of a shapes def calculate_area(name):\ # converting all characters # into lower cases name = name.lower() # check for the conditions if name == "rectangle": l = int(input("Enter rectangle's length: ")) b = int(input("Enter rectangle's breadth: ")) # calculate area of rectangle rect_area = l * b print(f"The area of rectangle is {rect_area}.") elif name == "square": s = int(input("Enter square's side length: ")) # calculate area of square sqt_area = s * s print(f"The area of square is {sqt_area}.") elif name == "triangle": h = int(input("Enter triangle's height length: ")) b = int(input("Enter triangle's breadth length: ")) # calculate area of triangle tri_area = 0.5 * b * h print(f"The area of triangle is {tri_area}.") elif name == "circle": r = int(input("Enter circle's radius length: ")) pi = 3.14 # calculate area of circle circ_area = pi * r * r print(f"The area of circle is {circ_area}.") elif name == 'parallelogram': b = int(input("Enter parallelogram's base length: ")) h = int(input("Enter parallelogram's height length: ")) # calculate area of parallelogram para_area = b * h print(f"The area of parallelogram is {para_area}.") else: print("Sorry! This shape is not available") # driver code if __name__ == "__main__" : print("Calculate Shape Area") shape_name = input("Enter the name of shape whose area you want to find: ") # function calling calculate_area(shape_name) Output: Calculate Shape Area Enter the name of shape whose area you want to find: rectangle Enter rectangle's length: 10 Enter rectangle's breadth: 15 The area of rectangle is 150. Comment More infoAdvertise with us Next Article Draw Diamond shape using Turtle graphics in Python Z zetareticuli34 Follow Improve Article Tags : Python school-programming Practice Tags : python Similar Reads Create different shapes using Canvas class in Tkinter - Python Tkinter, the standard Python library for creating graphical user interfaces (GUIs), provides a powerful widget called the Canvas that allows us to draw and manipulate shapes. The Canvas widget in Tkinter is an excellent tool for building 2D graphics. Our task is to create various shapes such as oval 2 min read Pycairo - Creating different shapes In this article we will see how to create different shapes using Pycairo in Python. In pycairo there are mainly two shapes rectangle and the arch which is used to make other shapes like square or semi-circle. Polygon shapes are created with the help of lines. An SVG file is a graphics file that use 2 min read Calculate the area of an image using Matplotlib Let us see how to calculate the area of an image in Python using Matplotlib. Algorithm: Import the matplotlib.pyplot module.Import an image using the imread() method.Use the shape attribute of the image to get the height and width of the image. It fetches the number of channels in the image.Calcul 1 min read Python | Drawing different shapes on PyGame window Pygame is a cross-platform set of Python modules designed for writing video games. It includes computer graphics and sound libraries designed to be used with the Python programming language. Now, itâs up to the imagination or necessity of developer, what type of game he/she wants to develop using th 3 min read Draw Diamond shape using Turtle graphics in Python In this article, we are going to learn how to draw the shape of a Diamond using turtle graphics in Python. Turtle graphics: forward(length): moves the pen in the forward direction by x unit.right(angle): rotate the pen in the clockwise direction by an angle x.left(angle): rotate the pen in the antic 2 min read How to Create custom Turtle shapes in Python? In Turtle, by default, we have an arrowhead-shaped cursor for drawing on the canvas. This can be changed to some other predefined shape or we can also create a custom shape and register it under a name. Not just that, we can even use gif format images to replace our cursor. Changing cursor to predef 2 min read Like