1 2 3 |
number
=
int ( input ( “enter a number: “ ) ) sqrt
=
number
* *
0.5 ( “square root:” ,
sqrt ) |
Output: enroll a issue : 64
square root : 8.0
In above program, first we ’ ra taking a total from user as input signal and the accede value will be converted to int from string and will store into variable star called number. then we are using advocate ( ** ) sign, which is used to find out the baron of a total. But we know that if a count have exponent ½ or 0.5 then it will represent to the square root of that number. That ’ second why we are using 0.5 as ability here. So the number**0.5 will give us square root of that number and will be stored in varying named as sqrt. In last line we ’ ra barely printing the feather root of the count. 2. Using math.sqrt() Method
1 2 3 4 |
import
math number
=
int ( input ( “enter a number:” ) ) sqrt
=
math . sqrt ( number ) ( “square root:”
,
sqrt ) |
sqrt() is the predefined method used to find square solution in python. But we have to import math module to use the sqrt() method. In first base credit line, we ’ rhenium importing math module, then in adjacent line, taking remark from user. After that we ’ re finding the straight solution of the number using sqrt() method and consequence will be stored into sqrt variable. In death line, just printing the square root as in first program. 3. Using math.pow() Method
1 2 3 4 |
import
math number
=
int ( input ( “enter a number:” ) ) sqrt
=
math . pow ( number ,
0.5 ) ( “square root: “ ,
sqrt ) |
pow() is besides a predefined method acting to find out exponent of a issue, it takes two arguments as stimulation, first base is the act itself and second one is baron of that numeral. The program is lapp as first platform where we ’ ra using ( ** ) signal to find out the public square root but entirely different is this that here we ’ rhenium using a predefined method acting pow() alternatively of ( ** ) sign to get the ability of that number. If you ’ ve any problem related with article or have any other possible means to find square solution in python then please let us know in comments .