Q1: Write a program to accept side of a square from user and calculate its area and perimeter. Display the side , calculated area and perimeter on the screen.
PYTHON QUESTION
Answers
Answer:
s=int(input("Side : "))
area=s*s
perimeter=4*s
print("Area of Rectangle : ",area)
print("Perimeter of Rectangle : ",perimeter)
sideOfSquare = float(input("Enter the side of square: "))
areaOfSquare = sideOfSquare * sideOfSquare
perimeterOfSquare = 4 * sideOfSquare
print("Side of square is ", sideOfSquare)
print("Area of square is ", areaOfSquare)
print("Perimeter of square is ", perimeterOfSquare)
The above program will help you to print the side, calculated area, and perimeter of the square.
Explanation
The program takes an input from the user that is the side of the square and stores it in the variable sideOfSquare.
After that, as we know to calculate
Area of Square = Side * Side
Perimeter of Square = 4 * Side
The same formulas are assigned to variables areaOfSquare and perimeterOfSquare respectively which gives us the required values.
print() statement is used to print out the values as asked in the question.
Extra Information
Python is created by Guido van Rossum and came into existence in 1991. It is a high-level and general programming language. It is a very lucid programming language as it has a good language construct and object-oriented approach. It is dynamically typed and garbage-collected.