top of page

rectangle_area_calculator.py

# This program calculates the area of a rectangle

# Function to calculate the area of a rectangle

def calculate_rectangle_area(length, width):

"""

Calculates the area of a rectangle.

Parameters:

length (float): The length of the rectangle.

width (float): The width of the rectangle.

Returns:

float: The area of the rectangle.

"""

area = length * width

return area

# Function to display the result

def display_result(length, width, area):

"""

Displays the result of the area calculation.

Parameters:

length (float): The length of the rectangle.

width (float): The width of the rectangle.

area (float): The area of the rectangle.

Returns:

None

"""

print(f"The area of a rectangle with length {length} and width {width} is {area} square units.")

# Main function

def main():

"""

Main function to execute the program.

"""

# Ask user for the dimensions of the rectangle

length = float(input("Enter the length of the rectangle: "))

width = float(input("Enter the width of the rectangle: "))

# Calculate the area

area = calculate_rectangle_area(length, width)

# Display the result

display_result(length, width, area)

# Execute the main function

if name == "__main__":

main()


2 views0 comments

Recent Posts

See All

Numpy data

import numpy as np # Create two numpy arrays array1 = np.array([1, 2, 3]) array2 = np.array([4, 5, 6]) # Add the arrays result = np.add(array1, array2) print(result)

Data numpy

import numpy as np # Create two numpy arrays array1 = np.array([1, 2, 3]) array2 = np.array([4, 5, 6]) # Add the arrays result = np.add(array1, array2) print(result)

what are pandas, numpy, matplotlib

Pandas: Pandas simplifies data analysis by offering powerful data structures like DataFrames and Series. Whether it's cleaning messy data, aggregating information, or performing complex operations, Pa

Comments


bottom of page