Python | Calculate the square of a given number (3 different ways)

Here, we are going to execute a Python program that will print all numbers between 1 to 1000, which are detachable by 7 and must not be distinct by 5.

Given a range (which is 1 to 1000) and we have printed all numbers which are distinct bye 7 and not detachable by 5 in python.

Model:

 Input:
    Enter an integer numbers: 8

    Output:
    Square of 8 is 64

Rationale:

To execute this rationale, we will utilize a for and in a circle with run() strategy. The announcement of range() strategy with the base to the greatest range is range(begin, end+1).

What’s more, check the condition, that worth ought to be detachable by 7 and ought not to be separable by 5 (model code: ((cnt%7==0) and (cnt%5!=0)) ).

On the off chance that condition is valid, print the numbers.

Here, we are going to execute a Python program that will print all numbers between 1 to 1000, which are detachable by 7 and must not be distinct by 5.

Given a range (which is 1 to 1000) and we have printed all numbers which are distinct bye 7 and not detachable by 5 in python.

Program

# Python program to calculate square of a number
# Method 1 (using  number*number)

# input a number 
number = int (raw_input ("Enter an integer number: "))

# calculate square
square = number*number

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

Output

Enter an integer number: 8
    Square of 8 is 64 

To execute this rationale, we will utilize a for and in a circle with run() strategy. The announcement of range() strategy with the base to the greatest range is a range(begin, end+1).

What’s more, check the condition, that worth ought to be detachable by 7 and ought not to be separable by 5 (model code: ((cnt%7==0) and (cnt%5!=0)) ).

On the off chance that condition is valid, print the numbers.

Program:

# Python program to calculate square of a number
# Method 2 (using  number**2)

# input a number 
number = int (raw_input ("Enter an integer number: "))

# calculate square
square = number**2

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

Output

 Enter an integer number: 8
    Square of 8 is 64 

Program:

# Python program to calculate square of a number
# Method 3 (using math.pow () method)

# importing math library 
import math 

# input a number 
number = int (raw_input ("Enter an integer number: "))

# calculate square
square = int(math.pow (number, 2))

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

Output

Enter an integer number: 8
    Square of 8 is 64 

Leave a Comment

error: Alert: Content is protected!!