Python | Calculate square of a given number (3 different ways)
All Answers
total answers (1)
Severity: 8192
Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated
Filename: libraries/Filtered_db.php
Line Number: 23
total answers (1)
1) By multiplying numbers two times: (number*number)
To find the square of a number - simple multiple the number two times.
Program:
Output
2) By using Exponent Operator (**): (number**2)
The another way is to find the square of a given number is to use Exponent Operator (**), it returns the exponential power. This operator is represented by **
Example: Statement m**n will be calculated as "m to the power of n".
Program:
Output
3) By using math.pow() method: (math.pow(number,2)
pow(m,n) is an inbuilt method of math library, it returns the value of "m to the power n". To use this method, we need to import math library in the program.
The statement to import math library is import math.
Program:
Output
need an explanation for this answer? contact us directly to get an explanation for this answer