Write A Python Function To Calculate Area Of Square

Area of a square is equal to square off side of a square.  given the side of the square you have to multiply by itself to get the area of a square.  below is the formula area of a square


Area of a square = side * side

(or)

A = a ^ 2




Write A Python Function To Calculate Area Of Square

Define a function named find_area(),  take the input argument as a variable that is the side of a  square.  So the return value should be  square of the side of a square

def find_area(side):
   return side * side





In the main program, use the input function to ask a user to enter the side of a triangle then convert it into a floating point number.

Pass the side of a square by calling the function find area and get the return value and store it in the variable area.  using the print function in the area of a square.

a = float(input("Enter Side of Square : "))
area = find_area(a)
print("Area of Square is : ", area)




Final program
================

def find_area(side):
   return side * side


a = float(input("Enter Side of Square : "))
area = find_area(a)
print("Area of Square is : ", area)





Output
============

Enter Side of Square : 24
Area of Square is :  576.0




OUTPUT
==================

Enter Side of Square : 12.5
Area of Square is :  156.25



Write A Python Function To Calculate Area Of Square




Write A Python Function To Calculate Area Of Square

You can also use the double star operator to raise the side to the power of 2.  Modify the above program instead of multiplying sides with itself.

def find_area(side):
   return side ** 2


a = float(input("Enter Side of Square : "))
area = find_area(a)
print("Area of Square is : ", area)






Conclusion
================

Run the above program by providing different setup values to note down the result.

Post a Comment

0 Comments