A summary of the methods of calculating the square root and number of the arithmetic in Python

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.