Python calculates the square root of arithmetic and the approximate number, and python returns the square root of arithmetic.

Source: Internet
Author: User

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

Related Article

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.