Python Program to find area of square
Program
side = int(input("Enter the side of a square?\t"))
area = side * side
print ("The area of the square is {0}".format(area))
This program calculates the area of a square based on user input.
side = int(input("Enter the side of a square?\t"))
input()
function takes user input as a string.int()
function converts the input into an integer.- The user enters the length of one side of the square, stored in the variable
side
.
area = side * side
- The formula for the area of a square is:
[
\text{Area} = \text{side} \times \text{side} ] - The result is stored in the variable
area
.
print("The area of the square is {0}".format(area))
- Displays the calculated area using
format()
function for string formatting.
Key Takeaways:
- Uses
input()
to take user input for the side of the square. - Computes the area using the formula ( \text{side} \times \text{side} ).
- Uses
format()
for clean output formatting.
This program provides a simple way to calculate the area of a square in Python.
Output
Enter the side of a square? 5
The area of the square is 25