Python algorithm practice week1- fundamentals of programming
編輯:Python
0x00 machine language 、 Assembly language and high-level language ( With 2+3 For example )
machine language :01 Code 、CPU Cognitive language
Add operation :1001
Subtraction operation :1010
2+3:1001 0010 0011
assembly language : Human readable mnemonics have been added to machine language
Add operation :ADD
Subtraction operation :SUB
2+3:ADD 2,3
High-level language : A language close to natural language
sum = 2 + 3
0x01 How programming languages work
A compiled
Convert high-level language source code into object code ( machine language )
The program can run directly
The execution speed of the object code is fast
Representative language :C/C++
interpreted
Convert high-level language source code into object code one by one , Executing while converting
Each time you run a program, you need source code and an interpreter
It has good cross platform portability
Representative language :Java、Python
0x02 Program flow chart
Use a specified series of figures 、 Flow line and text explain the basic flow and control flow in the algorithm .
The basic elements of the flowchart include
A box representing the corresponding operation
Flow lines with arrows
Necessary text inside and outside the box
Sequential structure
The Fahrenheit temperature is described by a sequential structure F Convert to Celsius C The process of
The formula :C = 5/9*(F-32)
algorithm flow chart
Python Code implementation
Branching structure
Find the absolute value of a given number
algorithm flow chart
Python Language implementation
# Branching structure , Find the absolute value
R = int(input(' Please enter a number R:'))
if(R >= 0):
print('R The absolute value of is {}'.format(R))
else:
print('R The absolute value of is {}'.format(-R))
Loop structure
Input n Value , seek 1 To n Continuous addition and