Python Program to Calculate Square of a Number

27-Oct-2022

.

Admin

Python Program to Calculate Square of a Number

Hi Dev,

In this post, we will learn Python Program to Calculate Square of a Number. I would like to show you Python in Calculate square of a given number. step by step explain Find square of a number in Python. you will learn Python program to find square using arithmetic operator. follow bellow step for How to Square a Number in Python.

Python program to find square of a number; In this tutorial, you will learn how to find or calculate square of a number in python using function, exponent operator.

There are a following python programs to find or calculate square of a number; as shown below:

Example 1: Python program to find the square of 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: 4

Square of 4 is 16

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

# 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: 8

Square of 8 is 64

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

# 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: 7

Square of 7 is 49

I hope it can help you...

#Python