In this python tutorial, you will learn about the Python program to find the area of square and, also we will check:
- How to find the area of square in Python
- Python program to find the area of square by getting input from a user
- Python program to find the area of a square using function
- How to find area and perimeter of a square in Python
Python program to find the area of square
Let see python program to find the area of square
- In this example, we will define the height of any one side of the square as “side”.
- Now, calculate the area of the square by using the formula as Area = side*side
- At last, print the area of the square to get the output.
Example:
side = 6
Area = side*side
print("Area of the square="+str(Area))
You can refer to the below screenshot to see the output for the python program to find the area of a square.
The above code we can use to find the area of square in Python.
You may like, Python program to find an area of a rectangle and How to find area of a triangle in Python?
Python program to find area of a square by getting input from a user
Here, we will see python program to find the area of the square by getting input from a user
- Firstly, we will take input from the user for the side value of the square using the input() method.
- Now, calculate the area of the square by using the formula as Area = side*side
- At last, print the area of the square to get the output.
Example:
side = int(input("Enter the side:"))
Area = side*side
print("Area of the square="+str(Area))
You can refer to the below screenshot to see the output for the python program to find the area of the square by getting input from a user.
This is the Python program to find area of a square by getting input from a user.
Also read, How to calculate area of a circle in Python?
Python program to find area of a square using function
Now, we will see python program to find the area of a square using function
- Firstly, we will define a function with arguments using def keywords.
- Now, we will calculate the area of a square inside the function by using the formula Area = side*side.
- Here, the side=12 is defined and the value is passed to the function argument.
- At last, print the area of a square to get the output.
Example:
def Areaofsquare(side):
Area = side*side
return Area
side = 12
print(Areaofsquare(side))
You can refer to the below screenshot to see the output for the python program to find the area of a square using function.
The above code is to find area of a square using function in Python.
Check out, How to calculate simple interest in Python?
Python program to find area and perimeter of a square
Let’s see python program to find area and perimeter of a square.
- Firstly, we will take input from the user for the side value of the square using the input() method.
- Now, calculate the area of the square by using the formula Area = s*s.
- Next, we will calculate the perimeter of a square by using the formula Perimeter=4*s
- At last, print the area and perimeter of the square to get the output.
Example:
s=int(input("Enter the side : "))
Area=s*s
Perimeter=4*s
print("Area of rectangle : ",Area)
print("Perimeter of rectangle : ",Perimeter)
You can refer to the below screenshot to see the output for the python program to find area and perimeter of a square.
The above code is to find area and perimeter of a square in Python.
You may like the following Python tutorials:
- Python program to print pattern
- How to print factorial of a number in Python
- How to swap two numbers in Python
- How to Print Python Fibonacci series
- How to subtract two numbers in Python
- PdfFileReader Python example
In this Python tutorial, we have learned about the Python program to find the area of square. Also, we covered these below topics:
- Python program to find the area of square
- Python program to find the area of square by getting input from a user
- Python program to find the area of a square using function
- Python program to find area and perimeter of a square
I am Bijay Kumar, a Microsoft MVP in SharePoint. Apart from SharePoint, I started working on Python, Machine learning, and artificial intelligence for the last 5 years. During this time I got expertise in various Python libraries also like Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… for various clients in the United States, Canada, the United Kingdom, Australia, New Zealand, etc. Check out my profile.