I was working 15 ----

# Operational requirements: The following drawing all the code and analysis code execution flow 
# 1, subject to the definition phase, the first nesting relationship shown in FIG namespace
# 2, and then locate the called function, function calls to write the code execution, when it comes to find the name, referring to 1-in-picture good
# nested chart, indicating the search order, layer by layer until you find the location


# ================= == =================== a topic
input = 333


DEF FUNC ():   # 2 execute the function body of the code 
    input = 444   # . 3 local variable name input = 444, 444 bind to the local memory address of the input variable name


FUNC ()   # 1 function is called back to the stage function definition function 
print (input)   # 4 print function call, look for input in the global name space, find the corresponding memory address input



# =================== title two ===================
DEF FUNC ():   # 2 execute function body 
    print (x) # . 3 i.e. the local name space is not found x function definition stage, need to global name lookup 
             # 5 calls the print function, x find the corresponding memory via the global name address 
the X-111 =    # 4 found in the global namespace of the X- 

FUNC ()   # function is called back to the stage-defined functions

# =================== title three ===================
. 1 = x # . 7 found in the global namespace x 
DEF func ():   # . 5 perform func function body 
   print (x)   # . 6 print function call, the current position x is not found, layer by layer from the current position to find x 
             # 8 the x value passed to the print function, to find the memory address corresponding to the name of the global variable x

DEF foo ():   # 2 execute foo function body 
    X = 222    # . 3 foo function of the local name space = 222 X 
    func ()   # . 4 func function call, the function func back to the definition phase 

foo () # . 1 call foo function, back to the definition phase function foo

# =================== title four ===================
INPUT = 111
 DEF f1 ():   # 2 perform f1 function body code 
    DEF f2 (): # . 5 performs f2 function body code 
        INPUT = 333   # f2 local name space INPUT = 333 
        print (INPUT) # call the print function, Finding the current position x, find the local name space is present f2 x, x corresponding to find the memory address by 
    INPUT = 222   # . 3 F1 = local name space 222 INPUT 

    f2 () # . 4 calls the function f2, f2 back to the definition of the function stage 

f1 ()   # 1 calls the function f1, f1-defined function return to stage
INPUT = 111
 DEF f1 ():   # 2 code execution f1 function in vivo 
    DEF f2 (): # . 5 code execution f2 function in vivo 
        # INPUT = 333 
        print (INPUT) # . 6 calls the print function, find x in the current position, there is no found, to the local name space is found, f1 
                     # 8 x passed to the print function to find the corresponding memory address x 
    INPUT = 222   # . 3 f1 = local name space 222 INPUT 
                # . 7 found in the local name space f1 x 
    F2 () # call the function 4 f2, f2 back to the definition phase function 

f1 ()   # 1 calls the function f1, f1 function back to the definition of stage

# =================== title five ===================
= 111 X
 DEF FUNC ():
     Print (X)   # as a function of the definition phase prevail, 
              # definition phase has produced local variable x, but this is called local variables are previously defined. Nested namespaces is determined when detecting syntax 
    x = 222

func()


# =================== title six ===================
x = 111   # . 4 found in the global space x 
        # . 9 found in the global space x 
DEF foo (): # 2 performs the function foo body of code 
    print (x,)   # . 3 calls the print function, find x from the current position, not found, to the global namespace to find x 
               # . 5 x to pass values to the print function, by x find the corresponding memory address 
DEF bar ():   # . 7 performs the function bar body of code 
    print (x) # . 8 calls the print function, the current location-finding x, is not found, go global name space to find x 
               # 10 x pass the value to the print function, by x locate the memory address corresponding 

foo () # 1 to call the function foo, foo back function definition phase 
bar ()   # 6 call the bar function, the function definition stage back bar


# =================== title seven ===================
1 x =   # . 6 global namespace x = 1, and X 1 memory address binding 
DEF func2 ():   # 2 performs the function body func2 code 
    func1 ()    # . 3 function func1 call back function definition phase 

X = 2 # 7 binding relationship between x and release a memory address, the memory address 2 binding 
DEF func1 ():   # . 4 performs code vivo func1 
    print (x)   # . 5 calls the print function, from the current position x start looking, did not find the need to go global namespace lookup 
#                9 will be found in the global namespace x passed to the print function, found by x corresponding memory address 

x 3 =   # 8 x will be between 2 and memory address binding relationship lifted, and memory address 3 binding 

func2 ()   # 1 calls the function func2, back to the stage-defined functions

# =================== title eight ===================

1, the following global variables currently logged records users log in to write function, once the user logs in successfully, then the global variable assignment for the currently logged on user name
login_user = None
2, for the balance of the query written before the function, add additional logic: if the user is not logged in, log in to perform Features

login_user = None
log_dic = {'login':None}

def login(user):
    December = {}
    with open('info', 'r', encoding='utf-8') as f:
        for line in f:
            name, pwd = line.strip().split(':')
            dic[name] = pwd

    the while True:
         # the User the INPUT = ( 'your name:') 
        IF the User not  in dic:
             # Print ( 'username does not exist') 
            return  ' user name does not exist ' 
        the else :
             the while True:
                password = INPUT ( ' Enter password: ' )
                 IF password == DIC [User]:
                     Global login_user
                    login_user = user
                    log_dic [ ' Login ' ] = User
                     return F ' {} login_user successful login ' 
                the else :
                     Print ( ' please enter password ' )
                     Continue




# 2, for the balance of the query written before the function, add additional logic: if the user is not logged in, log in to perform the function

def query(user):
    December = {}
    with open('query','r',encoding='utf-8') as f:
        for line in f:
            name,money = line.strip().split(':')
            dic [name] = Money
     # judge whether the user has landed 
    IF  not log_dic.get (the User):
         Print ( ' Login ' )
        login(user)

    return F ' {} User students, your balance DIC {[User]} '


username = input('your name:')
res1 = query(username)


print(res1)

 






Guess you like

Origin www.cnblogs.com/Kathrine/p/12526778.html
Recommended