Write a program in python to find the area and perimeter of a rectangle and
a square (program should take input from user i.e. length and breadth for rectangle and side for square).
Answers
Answered by
4
l= float(input("Enter the length:"))
b=float(input("Enter the breadth:"))
unit= str(input("Enter unit:")) #i.e cm, m etc
pm= 2*(l+b)
area= l*b
if l==b:
print("The shape is a square")
print("The perimeter of square is", pm, unit,"and the area is", area,"square", unit)
else:
print("The shape is a rectangle")
print("The perimeter of the rectangle is", pm,unit,"and the area is", area,"square",unit)
Enter the length: 5
Enter the breadth:6
Enter unit: cm
The shape is a rectangle
The perimeter of the rectangle is 22.0 cm and area is 30.0 square cm
Answered by
2
Similar questions