As we know how to find the square area mathematically because in this programming tutorial we are going to use simple maths formula for the square area. There are several methods to manipulate that area formula in programming. A number of methods are given below to solve this problem. Before jumping on the programming part, let’s discuss the formula.
Area Of Square = Side*Side
It means we have to take one parameter from the user to find the area of a square and that parameter is the side. You can see the calculation in the below image.
01. Method
Using Function and math library.
import math def findArea(r): areaOfSquare = pow(r,2) return areaOfSquare
side = float(input("Enter Side Of Square: ")) area = findArea(side) print("Area Of Square: ",area)
Output:
Enter Side Of Square: 2 Area Of Square: 4.0
02. Method
Using simple python and maths expressions.
side = float (input ("Enter Side: ")) area = side * side print (" Area Of Square: ", area)
Output:
Enter Side Of Square: 2 Area Of Square: 4.0
03. Method
Using simple python and direct area formula.
side = float (input ("Enter Side: ")) print (" Area Of Square: ", (side**2))
Output:
Enter Side Of Square: 2 Area Of Square: 4.0
04. Method
Using class and object concepts.
class squareArea: def __init__(self, side): self.side = side def area(self): return (self.side ** 2) s = float (input ("Enter Side: ")) square1 = squareArea(s) print("Area of circle:",square1.area())
Output:
Enter Side Of Square: 2 Area Of Square: 4.0