How to Calculate Area of Figures using Python

Hi all, Greetings of the day & welcome to Technifyed this is Vasav and today I’ll teach you how to calculate the area of Figures using Python

So, Let’s Start:

Here’s the very first line

def tri_area(base, height, unit):

We know that we need to start a function def. tri_area is the name of our function and then we have three variables namely base, height & unit.

print(str((base * height) / 2) + " sq " + unit) 

I know this line of code is a bit/ difficult to understand but I’ll try to make it easy for you.

Let’s start from the innermost bracket. That is the formula for calculating the area of a triangle using python. We’ve put str there because we need to add a string to it and the str function will help with that. Sq means Square and the unit is variable.

This is code in all:

def tri_area(base, height, unit):

    print(str((base * height) / 2) + " sq " + unit)

The input you will give:

tri_area(5, 6, 'm')

Output:

15 sq m 

Like this, I’ll now give you the code for three more shapes square, rectangle & circle-

def sqr_area(side, unit):     print(str(side*side) + ' sq ' + unit)       def rect_area(length, breadth, unit):     print(str(length * breadth) + ' sq ' + unit)      def circ_area(radius, unit):     pi = 3.14     print(str(pi * (radius**2)) + ' sq ' + unit)

Also Read:

Meta Front-End Developer Professional Certificate: A Roadmap to Success

See also  Python Interview Questions For Absolute Freshers

Latest

test

Voyager Scholarship: Voyager Scholarship 2025 Application, Enrollment & Tips

The Voyager Scholarship is an esteemed program that provides...

Spokeo Artificial Intelligence Scholarship 2024 Application, Enrollment & Tips

Artificial Intelligence (AI) has become an integral part of...

Pizza Hut Scholarship: Pizza Hut Scholarship 2024 Application, Enrollment & Tips

The Pizza Hut Scholarship Program is a post-high school...

Newsletter

Don't miss

test

Voyager Scholarship: Voyager Scholarship 2025 Application, Enrollment & Tips

The Voyager Scholarship is an esteemed program that provides...

Spokeo Artificial Intelligence Scholarship 2024 Application, Enrollment & Tips

Artificial Intelligence (AI) has become an integral part of...

Pizza Hut Scholarship: Pizza Hut Scholarship 2024 Application, Enrollment & Tips

The Pizza Hut Scholarship Program is a post-high school...
Vasav Trehan
Vasav Trehanhttps://technifyed.com
Vasav is the brain behind Technifyed.com. His love for Technology and Programming led him to kick-start this flabbergasting website and his Instagram account @technifyedofficial. His motive is to Simply Tech for Everyone.

test

Voyager Scholarship: Voyager Scholarship 2025 Application, Enrollment & Tips

The Voyager Scholarship is an esteemed program that provides financial aid, opportunities, and support to students aspiring to pursue a career in public service....

Spokeo Artificial Intelligence Scholarship 2024 Application, Enrollment & Tips

Artificial Intelligence (AI) has become an integral part of our modern world and is transforming various industries. As a result, several organizations are providing...