Analysis and summary of how Python calculates the square root and the approximate number of arithmetic values

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

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.