This article mainly introduces the relevant information summarized in Python's method of finding square roots and divisors of arithmetic numbers. Friends in need can refer to it
1. Find the arithmetic square root
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 a else: print x,'is a negative number'
2. Find the divisor
Method one:
pisor = [ ] x=int(raw_input('Enter a number:')) i= while i<=x: if x%i ==: pisor.append(i) i = i + print 'pisor:',pisor
Method two:
pisor = [ ] x=int(raw_input('Enter a number:')) for i in range(,x+): if x%i ==: pisor.append(i) # 此行也可以换成 pisor = pisor + [i] print 'pisor:',pisor
Let me introduce you to the Python sqrt() function
Description
sqrt() method returns the square root of the number x.
Syntax
The following is the syntax of the sqrt() method:
import math math.sqrt( x )
Note: sqrt() cannot be accessed directly. You need to import the math module and call this method through a static object.
Parameters
x -- Numeric expression.
Return value
Returns the square root of the number x.
Example
The following shows an example of using the sqrt() method:
#!/usr/bin/python import math # This will import math module print "math.sqrt(100) : ", math.sqrt(100) print "math.sqrt(7) : ", math.sqrt(7) print "math.sqrt(math.pi) : ", math.sqrt(math.pi)
Above After running the example, the output result is:
math.sqrt(100) : 10.0 math.sqrt(7) : 2.64575131106 math.sqrt(math.pi) : 1.77245385091
For more analysis and summary of Python methods for finding square roots and divisors of arithmetic, please pay attention to the PHP Chinese website for related articles!