PYTHON-ZX Note 3-functions

Source: Internet
Author: User

First, call the function

On the interactive command line by help(abs) looking at abs the Help information for the function

Assign a function name to a variable

A = ABS

Second, define the function

Solution equation: ax2 + bx + c = 0

1 #-*-coding:utf-8-*-2 3 ImportMath4 5 defquadratic (A, B, c):6n = b*b-4*a*C7     ifN <0:8         return("this equation has no solution")9     elifn = =0:Ten         returnb/2*a One     Else: AX1 = (-B + math.sqrt (n))/(a) -x2 = (-b-math.sqrt (n))/(a) -         returnx1,x2 the  - #Test: - Print(Quadratic (1,2,1)) - Print(Quadratic (4,2,2)) +  -  + #print (' Quadratic (2, 3, 1) = ', quadratic (2, 3, 1)) A #print (' Quadratic (1, 3,-4) = ', quadratic (1, 3,-4)) at #if quadratic (2, 3, 1)! = ( -0.5, -1.0): - #print (' Test failed ') - #elif Quadratic (1, 3,-4)! = (1.0, -4.0): - #print (' Test failed ') - #Else: - #print (' Test successful ')

Iii. parameters of the function

PYTHON-ZX Note 3-functions

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.