Write A Python Script To Input Side Of A Square And Display Its Area

In this article let's take a side of a square is input to the python script and calculate the area of a square, Finally print the  area of a square as output of the program

The program has only three lines of code,  the area of a square is represented by square of sides of square i.e,

Area = side ^ 2 (or)
Area = side * side

Let's use the above formula to find the area of a square.

 

Write A Python Script To Input Side Of A Square And Display Its Area

 

 


Write A Python Script To Input Side Of A Square And Display Its Area

Let's take a new variable named aside and ask the user to enter the side of a square using the input function call,  then convert the input to floating point value.

side = float(input("Enter Side of Square : "))




Take another variable name as area and compute the area of a square by multiplying the sides by itself.  Once the area of a square is calculated, use the print function call to print the area of a square.

area = side * side

print("Area of a Square is : %.2f" %area)




Python Script
=========================

side = float(input("Enter Side of Square : "))

area = side * side

print("Area of a Square is : %.2f" %area)




Output
================
Enter Side of Square : 12
Area of a Square is : 144.00



Output
==============
Enter Side of Square : 23.9
Area of a Square is : 571.21




Output
==============
Enter Side of Square : 22.90
Area of a Square is : 524.41




Conclusion
=====================
Execute the above python script by providing the sides of a square as input to the program and note down the results.

Comment it down below if he has any suggestions to improve the Python program.




Post a Comment

0 Comments