1つの関数を書いて3回のログイン機能を完了し、もう1つの関数を書いて登録機能を完了します(コードと拡張)

5685 ワード

#     :
def regist(username,password):
    with open('memory',mode='r+',encoding='utf8') as f1:
        for line in f1:
            if line == ' ':  #    
                continue
            index = line.find('_')            #python find()   index()     , index         ,    , find    -1.
            memory_name = line[0:index]          #find() index()   https://www.cnblogs.com/40kuai/p/6262297.html
            if username == memory_name:
                return False
        else:            #     else   ,    for     ,   for       
            f1.write(''+username +'_'+ password+'
') return True res = regist(input(''),input('')) if res: print(' ') else: print(' , ') # # def login(username,password): # with open('memory',mode='r+',encoding='utf8') as f2: # for line in f2: # if line.strip() == username +'_'+password: # return True # else:      # else , if , return ,for # return False # for i in range(2,-1,-1): # res = login(input(''),input(''))  # , , res , # if res: # print(' , 。') # break # else: # print(' , %d '%i)