How to Find Square of  Number in Python

How to Find Square of Number in Python

The objective of this Python post, you will see various Python programs that cover the following:

  • Python program to find the square of given number
  • Python program to find given number Using math power() function
  • Python program find a square of given number using Exponent Operator

Now let’s see each one by one:

1: Python program to find the square of given number

  • Take input number from the user
  • Calculate the square of given number using * operator
  • Display square of the given number
# Python program to calculate square of a number
# Method 1 (using  number*number)

# take input a number from user
num = int(input("Enter an any number: "))

# calculate square using * operator
sq = num*num

# display result
print("Square of {0} is {1} ".format(num, sq))

Output

Enter an any number:  5 
Square of 5 is 25  

2: Python program to find given number Using math pow() function

  • Take input number from the user
  • Calculate the square of the given number using math pow() function
  • Display square of the given number
# Python program to calculate square of a number using math module

# importing math module 
import math 

# take input a number from user
num = int(input("Enter an any number: "))

# calculate square using pow() function
square = int(math.pow (num, 2))

# display result
print("Square of {0} is {1} ".format(num, square))

Output

Enter an any number:  7 
Square of 7 is 49  

3: Python program find a square of given number using Exponent Operator

  • Take input number from the user
  • Calculate the square of given number using Exponent Operator
  • Display square of the given number
# Python program to calculate square of a number using Exponent Operator

# take input from user
num = int (input("Enter an any number: "))

# calculate square using Exponent Operator
sq = num**2

# print
print("Square of {0} is {1} ".format(num, sq))

Output

Enter an any number:  9 
Square of 9 is 81  

Leave a Reply

Your email address will not be published. Required fields are marked *