课堂练习:python 简单登录
while True: username = input('name:').strip() password = input('passwd:').strip() if len(username) != 0 and len(password) != 0: with open('user_file','r',encoding='utf8') as f: log_sucess = False f.seek(0,0) for line in f.readlines(): line = line.split() if len(line) != 0: if username == line[0] and password == line[1]: print('welcom %s'%username) log_sucess = True elif username == line[0] and password != line[1]: print('密码错误') else: print('用户不存在') if log_sucess: break else: continue

浙公网安备 33010602011771号