WAP to Calculate Area of Rectangle in Python. Calculating the area of the rectangle is a fundamental task in geometry and can also serve as a great introductory project for beginners learning Python programming.
Table of Contents
Python Program for Area of Rectangle
# get input from the user
width = float(input("Enter the width of the rectangle "))
height = float(input("Enter the height of the rectangle "))
# Calculate the area
area = width * height
print("The area of rtectangle is ", area)
Above code-
- Ask the user for input: Prompt the user to enter the width and height of the rectangle. You can use Python’s built-in function
'input()'
to receive input from the user. - Convert input to Float: In the input received from the
'input()'
function is a string, it needs to be converted into a float (or int) to perform arithmetic operations. - Calculate the Area: Use the formula for the area of rectangle ‘area = width x height’.
- Print the result: Finally, display the result using
'print()'
.
Happy Coding & Learning
1 thought on “WAP to calculate Area of Rectangle in Python”