This article mainly introduces the summary of Python's methods for finding the square root of arithmetic and the approximate number, for more information about how to calculate the square root and approximate number of Python, see this article.
I. 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'else:print aelse:print x,'is a negative number'
II. estimate the approximate number
Method 1:
pisor = [ ]x=int(raw_input('Enter a number:'))i= while i<=x: if x%i ==:pisor.append(i)i = i +print 'pisor:',pisor
Method 2:
Pisor = [] x = int (raw_input ('Enter a number: ') for I in range (, x +): if x % I =: pisor. append (I) # this line can also be changed to pisor = pisor + [I] print 'pisor: ', pisor
The following describes the Python sqrt () function.
Description
The sqrt () method returns the square root of the number x.
Syntax
The syntax of the sqrt () method is as follows:
import mathmath.sqrt( x )
Note: sqrt () cannot be accessed directly. you need to import the math module and call this method through static objects.
Parameters
X -- numeric expression.
Return value
Returns the square root of x.
Instance
The following shows an instance using the sqrt () method:
#!/usr/bin/pythonimport math # This will import math moduleprint "math.sqrt(100) : ", math.sqrt(100)print "math.sqrt(7) : ", math.sqrt(7)print "math.sqrt(math.pi) : ", math.sqrt(math.pi)
The output result is as follows:
math.sqrt(100) : 10.0math.sqrt(7) : 2.64575131106math.sqrt(math.pi) : 1.77245385091
For more Python analysis and summarization of arithmetic square root and approx!