Python Practice › If-Else Programs › Program 51
Is the rectangle a square?
Write a Python program that takes the length and breadth of a rectangle and checks whether it is a square.
Input
length 4, breadth 5
Output
Length: 4 Breadth: 5 It is not a square
Approach
- A rectangle is a square when length equals breadth.
Solution
length = float(input("Length: "))breadth = float(input("Breadth: "))if length == breadth: print("It is a square")else: print("It is not a square")Outputtyped input: 4, 5
Length: 4 Breadth: 5 It is not a square
Line by line
Lines 1-2
float() accepts decimal lengths too.
Learn the concept
New to this topic? Read the lesson, then come back.