Chapter III (first procedure) knowledge points induction
Programming is like writing a script. Python functions are not very different from scripts, you can call functions repeatedly, and it executes a predetermined "script" (the script can also refer to the entire program) every time.
In Python idle, real programming begins with writing functions.
Canada, Celsius.
Fahr = Cels * 1.8 + or Cels = (fahr–32)/1.8
Celsius: at 1 standard atmospheric pressure freezing point for 0 degrees, boiling point of 100 degrees, the temperature is divided into a description
Fahrenheit: at 1 standard atmospheric pressure freezing point of 32 degrees, boiling point of 212 degrees, the temperature is divided into a description
Create a custom function using the keyword def such as:
def convert (Fahr):
Cels = Fahr * 1.8 + 32.0
Return cels
These statements associate the symbolic name convert with a callable object (here is a function)
With regard to indentation, in idle, you can use the indentation that is automatically created for you; When you write a Python script in a stand-alone file, you use 4 spaces to indent it (instead of using a tab).
In fact, any indentation scheme is feasible, as long as the indent amount is the same each time. However, many Python programmers follow the PEP-8 Standard, which is considered to be the best choice for indenting 4 of spaces. In summary, either a tab character (a tab that looks like 4 spaces) is used, but there is only one char, or multiple spaces are used. The safest strategy is to have the text editor follow the rules for replacing tabs with spaces.
1 inches = 2.54 cm
Variables that are defined inside the function, regardless of the variables outside the function.
A function must be defined before it can be called.
Print message: Built-in function print ()
quotation marks (single, double, triple, three pairs) indicate that the words are printed as-is.
It can be learned that adjacent strings or empty characters or spaces separated, can be automatically spliced .
You can also export multiple parameters, by default, insert a space between adjacent items, and it will print a newline character after all the content is printed, causing the terminal to wrap.
There is no need to output content, print a newline character directly, and generate a blank line.
The golden ratio phiφ, one of the special properties of this number is that its square minus 1 is the result of itself .
phi = 1/phi + 1
Phi is a long edge shorter than a short edge; 1/phi is shorter than long edge
Gets the string input, built-in function input (), the basic function is to get and return a text string.
int and float are actually the names of the built-in data type integers and floating-point numbers, respectively. In Python, it is usually possible to use the type name to perform the conversion (as appropriate, if the conversion is possible). The input content, as long as it is allowed by this data type, can be converted.
Right Triangle area formula:A = width * Height * 0.5
Spherical volume formula:V = 4 * pi * r * * 3/3
Circle Area formula:A = pi * R * * 2
From Math import pi
Print () parameter Sep, the function is to specify the delimiter;end, the effect is print () after the output, do not wrap.
format Specifies a string:
Distance formula: The Pythagorean distance formula calculates the distance between two points on the Cartesian plane
The Pythagorean distance formula is derived from the Pythagorean theorem, the distance between two points is equal to the right triangle hypotenuse, the vertical distance and the horizontal distance is equivalent to the right triangle straight edge.
The third chapter of the "0 pressure python" knowledge points induction