Programming Paradigm
1, the different types of tasks, the use of different ways to solve the problem.
2. There are two kinds of programming paradigm
1. Process-oriented programming
2. Object-Oriented Programming
process-oriented programmingWhat is process-oriented programming?
Process-Steps to solve the problem
To solve a big problem
1, first to split the big problem into a number of small problems or sub-processes.
2. Then the sub-process is split into small problems or sub-processes
3, until the small problem can be solved in a small step in the range.
What are the pros and cons?
Advantages: The complexity of the problem flow, programming difficult.
Cons: Poor scalability
Write code:
Write a simple user registration program
#1 Write a user registration program#process-Oriented programming methods:#1. User Input account password#2. User input Legality detection#3. Write to Input library#Note:#Advanced : How do I change the email registration function when I need to increase it? ImportJSONdefInteractive ():#Step 1user = input ('>>'). Strip () PSW= Input ('>>'). Strip ()return { 'name': User,'pwd': PSW}defCheck (User_info):#Step 2Is_value =TrueifLen (user_info['name']) ==0:Print('user name cannot be empty') Is_value=FalseifLen (user_info['pwd']) < 6: Print('password cannot be less than 6 bits') Is_value=Falsereturn { 'Is_value': Is_value,'User_info': User_info}defRegister (Check_info):#Step 3 ifcheck_info['Is_value']: with open ('json.db','W', encoding='Utf-8') as F:json.dump (check_info['User_info'], F)defMain (): User_info= Interactive ()#Step 1Check_info = Check (user_info)#Step 2Register (Check_info)#Step 3if __name__=='__main__': Main ()
View Code
Increase input Email Registration
#1 Write a user registration program#process-Oriented programming methods:#1. User Input account password#2. User input Legality detection#3. Write to Input library#Note:#Advanced : How do I change the email registration function when I need to increase it? ImportJson,redefInteractive ():#Step 1user = input ('>>'). Strip () PSW= Input ('>>'). Strip () email=input ('>>'). Strip ()return { 'name': User,'pwd': PSW,'Email': Email}defCheck (User_info):#Step 2Is_value =TrueifLen (user_info['name']) ==0:Print('user name cannot be empty') Is_value=FalseifLen (user_info['pwd']) < 6: Print('password cannot be less than 6 bits') Is_value=Falseif notRe.search (R'@.*?\.com$', user_info['Email']): Print('Bad mailbox Format') Is_value=Falsereturn { 'Is_value': Is_value,'User_info': User_info}defRegister (Check_info):#Step 3 ifcheck_info['Is_value']: with open ('json.db','W', encoding='Utf-8') as F:json.dump (check_info['User_info'], F)defMain (): User_info= Interactive ()#Step 1Check_info = Check (user_info)#Step 2Register (Check_info)#Step 3if __name__=='__main__': Main ()
View Code
Application scenarios?
Once the feature is implemented, few changes are made to the scene. Scenarios such as automatic deployment scripts.
Object-oriented programming what is object-oriented programming?
What are the pros and cons?
Application scenarios?
Design and development of python-object-oriented programming