Python calculates the square root of arithmetic and the approximate number, and python returns the square root of arithmetic.
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:
divisor = [ ]x=int(raw_input('Enter a number:'))i= while i<=x: if x%i ==:divisor.append(i)i = i +print 'divisor:',divisor
Method 2:
Divisor = [] x = int (raw_input ('enter a number: ') for I in range (, x +): if x % I =: divisor. append (I) # This line can also be changed to divisor = divisor + [I] print 'divisor: ', divisor
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
Articles you may be interested in:
- How to solve the square root of Python
- How to Use the sqrt () method to calculate the square root in Python
- Evaluate the maximum common approx. and evaluate the prime number using Python
- How to Use Python to solve the maximum Common Divisor