Write a Python Program to Calculate the square of a Number using Arithmetic Operators and Functions with an example.
Python Program to Calculate Square of a Number
This Python program allows the user to enter any numerical value. Next, Python finds the square of that number using an Arithmetic Operator
# Python Program to Calculate Square of a Number
number = float(input(" Please Enter any numeric Value : "))
square = number * number
print("The Square of a Given Number {0} = {1}".format(number, square))
Python Square of a Number output
Please Enter any numeric Value : 9
The Square of a Given Number 9.0 = 81.0
Python Program to find Square of a Number Example 2
This Python square of a number example is the same as above. However, this time, we are using the Exponent operator.
number = float(input(" Please Enter any numeric Value : "))
square = number ** 2
print("The Square of a Given Number {0} = {1}".format(number, square))
Please Enter any numeric Value : 10
The Square of a Given Number 10.0 = 100.0
Python Program to find Square of a Number using Functions
In this Python program example, we are defining a function that returns the square of a number.
def square(num):
return num * num
number = float(input(" Please Enter any numeric Value : "))
sqre = square(number)
print("The Square of a Given Number {0} = {1}".format(number, sqre))
