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