Write a program to find the side of a square whose perimeter you read from user. Python Data Handling
As found in PriP 1.2, Data Handling. Class 12 Computer Science with Python by Sumita Arora is referred to in schools affiliated to but not limited to CBSE.
Q11. Write a program to find the side of a square whose perimeter you read from user.
We can find the length of side of square by the dividing parameter in four as a square has 4 sides. Therefore,
Perimeter = 4×Side
,
From this, we can derive the side length:Side = Perimeter / 4
Lastly, it needs to be written in Python to work for us.
Required Python Code
Python
# Program to find the side of a square given its perimeter
# Read the perimeter from the user
perimeter = float(input("Enter the perimeter of the square: "))
# Calculate the side length
side_length = perimeter / 4
# Display the result
print(f"The side length of the square is: {side_length}")
Example Usage and Output
If the user enters 20
as the perimeter, the output will be:
Output
The side length of the square is: 5.0