03 Python function

First, the function

1 determines whether or item is available, send the stock
DEF Goods (G):
 ku = [ 'A', 'B', 'C', 'D']
 IF ku in G:
 the Add ()
 the else:
 return False

DEF Check_Infor (name, Phone, the Add):
    is_ok = True
    IF name == '' or name == '':
        is_ok = False
    IF len (Phone) = 11:!
        is_ok = False
    IF not in the Add [ 'Beijing', ' Shandong ']:
        is_ok = False
    return is_ok



DEF the Add ():
    name = INPUT ( 'Enter your name:')
    Phone = INPUT ( 'Enter Telephone:')
    the Add = INPUT ( 'Enter Address:')
    RES = Check_Infor (name, Phone, the Add)
    IF RES :
        note ()
    return False


DEF note ():
    # send a message to the merchant
    print ( 'immediate shipment')


DEF Start ():
    print ( 'Welcome!')
    G = the INPUT ( 'commodity')
    goods (G)
start ()

 

 

 

2. registered users. Required to contain numbers and letters, a password is greater than 6, telephone, codes (one minute period, numerous retransmissions, sleep)
global_count = 0
DEF User ():
 users_ = INPUT ( "Please enter the account number: >> ')
 the Z = 'ZXCVBNMASDFGHJKLQWERTYUIOPzxcvbnmasdfghjklqwertyuiop'
 N = '1234567890'
 T = '.! * & ^% $ # @ ~'
 is_Z = False
 is_N = False
 is_T = True
 for I in users_:
 # letters
 IF I in the Z:
 is_Z = True
 # digital
 IF I in N:
 is_N = True
 # special characters
 IF I in T:
 is_T = False
 
 IF is_Z and is_N and is_T:
 PASS1 ()
 the else:
 . Print ( 'account must contain numbers and letters, and can not contain (* & ^% $ ! # @ ~) ')

DEF PASS1 ():
    password = iNPUT (' enter password: ')
    IF len (password)>. 5:
        Phone ()
    the else:
        Print ( 'password input failure')


DEF Phone ():
    Import Re, to complie ( 'str')
    compile.search
 
    Phone the INPUT = ( 'Please enter the phone:')
    IF len (Phone) = 11!:
        print ( 'invalid phone number')
    the else:
        verify_number ()


DEF verify_number ():
    Global global_count    


    Import Random
    Import Time
    START_TIME the time.time = ()
    RES = random.randrange (1000,9999)
    global_count + =. 1
    print ( 'codes : {} '. the format (RES))
    Input_ = int (iNPUT (' Please enter this code: '))
    END_TIME = the time.time ()
    SUB_TIME END_TIME = - START_TIME
    IF SUB_TIME> 10:
        global_count IF> 2:
            Print ( '. You might be a robot')
            Exit
        Print ( 'verification code expires, the upcoming retransmission')
        the time.sleep (2)
        verify_number ()
    the else:
        IF RES == Input_:
            Print ( 'verification code is ok, the user registration !!! the ok ')
        the else:
            ! Print (' error code ')
            the time.sleep (2)
            verify_number ()

DEF Start ():
    Print (' new user registration: ')
    the user ()
Start ( )

 

 

 

3.VIP and ordinary users buy
DEF Qiang (A):
    B = '[Jocker]'
    IF A in B:
        Print ( 'Congratulations')
    the else:
        Print ( 'sorry')
Qiang ( 'A')

 

 

 

4. The variable length parameter (sewer) * + [Name]
DEF the Add (* Jocker):
    Print (Jocker)

the Add (l, 2,3)

 

#
def rock(*jocker):
    sum_ = 0
    if len(jocker) == 0 :
        print('无效数字')
    else:
        for i in jocker:
            sum_ += i
    print(sum_)
rock(1,2,3,4,5,6,7)

 

 

 

The page calls between each other
#from [present page name] [function calls] Improt



6.as
#import K instead of K AS test test



7. anonymous function
# (the lambda X: Print (X)) (100)
# 00 >>

# 2 anonymous number adding function
(lambda a, b: print ( a + b)) (1,2)

Guess you like

Origin www.cnblogs.com/wx00/p/11284812.html