Calculate the Area and Perimeter for Shapes in Python


The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle.

This program is a simple Python script that calculates the area and perimeter of a rectangle and the area and circumference of a circle. It prompts the user to input the length, breadth of rectangle and radius of circle, and then uses these inputs to calculate and print out the results.

The program first prompts the user to input the length, breadth of rectangle and radius of circle using the input() function and assigns them to the variables "len", "bre" and "r" respectively. The int() function is used to convert the input from a string to an integer.

Next, the program calculates the area of the rectangle and assigns the value to a variable "area1" by multiplying the length and breadth of rectangle. It then calculates the perimeter of the rectangle and assigns the value to a variable "perimeter" by using formula 2*(length+breadth) It then calculates the area of the circle and assigns the value to a variable "area2" by using formula pirr and circumference of a circle and assigns the value to a variable "circum" by using formula 2pir

Finally, the program uses the print() function to output the results, including the area of the rectangle, perimeter of rectangle, area of circle and circumference of circle.


Source Code

'''
Area of Rectangle=l*b
Perimeter of Rectangle=2*(l+b)
Area of Circule=PI*r*r(PI=3.14)
Circum of a Circule=2*PI*r
'''
len=int(input("Enter the Lenth of rectangle:"))
bre=int(input("Enter the Breadth of rectangle:"))
r=int(input("Enter the Redius of Circle:"))
area1=len*bre
perimeter=2*(len+bre)
area2=3.14*r*r
circum=2*3.14*r
print("Area of Rectangle =",area1)
print("Perimeter of Rectangle =",perimeter)
print("Area of Circle =",area2)
print("Circum of Circle =",circum)

Output

Enter the Lenth of rectangle:10
Enter the Breadth of rectangle:12
Enter the Redius of Circle:23
Area of Rectangle = 120
Perimeter of Rectangle = 44
Area of Circle = 1661.06
Circum of Circle = 144.44


Example Programs