Python profram to calculate square of a given number
Given a number, the task is to write a Python program to calculate square of the given number.
Input: 4 Output: 16 Input: 3 Output: 9 Input: 10 Output: 100
We will provide the number, and we will get the square of that number as output. We have three ways to do so:
- Multiplying the number to get the square (N * N)
- Using Exponent Operator
- Using math.pow() Method
Method 1: Multiplication
In this approach, we will multiply the number with one another to get the square of the number.
Method 2: Using Exponent Operator
In this approach, we use the exponent operator to find the square of the number.
Exponent Operator: **
Return: a ** b will return a raised to power b as output.
Method 3: Using pow() Method
In this approach, we will use the pow() method to find the square of the number. This function computes x**y and returns a float value as output.
Syntax: float pow(x,y)
x : Number whose power has to be calculated.
y : Value raised to compute power.
Return Value :
Returns the value x**y in float.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course