Python, like C, has its own standard library, but in Python it's called a module, which is similar to a header file in C and a package in Java, where math is one of them, and the sin () and cos () functions are available in the Math module
The format for referencing modules in Python (in reference to the math example) is: Import Math
For an example that calculates the coordinates in the game:
Import Math def = x + Step *= y-step * math.sin (angle)return nx,xy
This allows the return value to be obtained at the same time:
X, y = Move (100,100,60,MATH.PI/6)print x, y>>>151.961524227 70.0
Do you feel this aspect is much stronger than C language?!
In fact, this is an "illusion", the return in Python is still a value!
R = Move (100,100,60,MATH.PI/6)print r>>>151.96152422706632, 70.0
The truth is that the returned result is printed with print and the returned value is a tuple!
Summary: Python's function returns a multivalued value that returns a tuple, but is easier to write.
Small problem:
The definition of a unary two-second equation is: ax2 + bx + c = 0
Write a function that returns the two solutions of the two-second equation.
Note: The Python math package provides the SQRT () function for calculating the square root.
Code:
Import Math def = (-B + math.sqrt (B*B-4*A*C))/(= (-b-math.sqrt (b*b-4*a*c))/(a)return X1,X2Print quadratic_equation (2, 3, 0)print quadratic_equation (1,-6, 5)
2017 Winter Vacation 0 Basic Learning the function of the Python series returns multiple values