Write a program to find area in python - Program to find area of rectangle in python - Program to find area of square in python - Program to find area of circle in python - Program to find area of triangle in python - Python Programs - Pattern programs in python
Program To Find Area In Python
1. Area of a rectangle
def rectangle_area(length, width):
"""
Returns the area of a rectangle with the given length and width.
"""
return length * width
# example usage
print(rectangle_area(5, 10)) # 50
Here is the practical of the above program in Jupyter Notebook
2. Area of a square
def square_area(side):
"""
Returns the area of a square with the given side length.
"""
return side ** 2
# example usage
print(square_area(5)) # 25
Here is the practical of the above program in Jupyter Notebook
3. Area of a circle
import math
def circle_area(radius):
"""
Returns the area of a circle with the given radius.
"""
return math.pi * radius ** 2
# example usage
print(circle_area(5)) # 78.53981633974483
Here is the practical of the above program in Jupyter Notebook
4. Area of a triangle
def triangle_area(base, height):
"""
Returns the area of a triangle with the given base and height.
"""
return 0.5 * base * height
# example usage
print(triangle_area(5, 10)) # 25.0
Here is the practical of the above program in Jupyter Notebook
These are just a few examples of programs to find the area of different shapes in Python. There are many more shapes for which you can calculate the area, such as trapezoids, parallelograms, and ellipses. The key is to understand the formula for calculating the area of the shape and to write a function that implements that formula in Python.
Comments
Post a Comment