This article mainly describes the Python to calculate the square root and the sum of the methods of the relevant data, the need for friends can refer to the following
One, the square root of arithmetic
A=x=int (Raw_input (' Enter a number: ')) if x >=: While a*a < x:a = a + if a*a! = X:print x, ' is not a perfect square ' els E:print aelse:print x, ' is a negative number '
Second, ask for approximate
Method One:
Pisor = []x=int (raw_input (' Enter a number: ')) i= while i<=x:if x%i = =:p Isor.append (i) i = i +print ' pisor: ', pisor
Method Two:
Pisor = []x=int (' Enter a number: ')] for I in range (, x+): if x%i = =:p Isor.append (i) # This line can also be changed to Pisor = Pisor + [i]p Rint ' pisor: ', pisor
Below you introduce the Python sqrt () function
Describe
The sqrt () method returns the square root of the number x.
Grammar
The following is the syntax for the sqrt () method:
Import mathmath.sqrt (x)
Note: sqrt () is not directly accessible, it needs to be imported into the math module and called by a static object.
Parameters
X--Numeric expression.
return value
Returns the square root of the number x.
Instance
The following shows an example of using the sqrt () method:
#!/usr/bin/pythonimport Math # This would import math Moduleprint "math.sqrt": ", math.sqrt (+) print" math.sqrt (7): ", Math.sqrt (7) print" Math.sqrt (Math.PI): ", Math.sqrt (Math.PI)
When the above instance is run, the output is:
MATH.SQRT (+): 10.0math.sqrt (7): 2.64575131106math.sqrt (Math.PI): 1.77245385091