鱼C论坛

 找回密码
 立即注册
查看: 2138|回复: 1

有些代码看不懂是什么意思,请指教!

[复制链接]
发表于 2020-9-8 15:16:37 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
同一账号输错三次锁定,(提示:锁定的用户存入文件中,这样才能保证程序关闭后,该用户仍然被锁定)
  1. tag = True
  2. dict = {}
  3. while tag:
  4.     inp_name = input("请输入账号>").strip()
  5.     with open(r'user.txt', mode='r', encoding='utf-8') as f:
  6.         if inp_name in f:
  7.             print('该账户已被锁定')
  8.             tag = False#[size=5][b]为什么这里要变成False??[/b][/size]
  9.             break#[size=5][b]这一段代码怎么理解?[/b][/size]
  10.     inp_paw = input('输入密码>')
  11.     with open(r'user.txt', mode='rt', encoding='utf-8') as f1:
  12.         for line in f1:
  13.             name, paw = line.strip().split(':')
  14.             if name == inp_name and paw == inp_paw:
  15.                 print('登陆成功')
  16.                 tag = False
  17.                 break
  18.             elif name == inp_name and paw != inp_paw:
  19.                 print('密码错误')
  20.                 if name not in dict:
  21.                     dict[name] = 0
  22.                 dict[name] = dict.get(name) + 1
  23.                 if dict[name] == 3:
  24.                     with open(r'user.txt', mode='a', encoding='utf-8') as f:
  25.                         f.write(name)
  26.                         print('该用户被锁定')
  27.                 break
  28.         else:
  29.             print('账号不存在')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2020-9-9 11:29:07 | 显示全部楼层
本帖最后由 suchocolate 于 2020-9-11 10:04 编辑
  1. tag = True
  2. dict = {}
  3. while tag:
  4.     inp_name = input("请输入账号>").strip()
  5.     with open(r'user.txt', mode='r', encoding='utf-8') as f:
  6.         if inp_name in f:
  7.             print('该账户已被锁定')
  8.             tag = False     #为什么这里要变成False? ---> false表示锁定
  9.             break      #这一段代码怎么理解? ---> 锁定了,就跳出循环,结束程序
  10.     inp_paw = input('输入密码>')
  11.     with open(r'user.txt', mode='rt', encoding='utf-8') as f1:
  12.         for line in f1:
  13.             name, paw = line.strip().split(':')
  14.             if name == inp_name and paw == inp_paw:
  15.                 print('登陆成功')
  16.                 tag = False
  17.                 break
  18.             elif name == inp_name and paw != inp_paw:
  19.                 print('密码错误')
  20.                 if name not in dict:
  21.                     dict[name] = 0
  22.                 dict[name] = dict.get(name) + 1
  23.                 if dict[name] == 3:
  24.                     with open(r'user.txt', mode='a', encoding='utf-8') as f:
  25.                         f.write(name)
  26.                         print('该用户被锁定')
  27.                 break
  28.         else:
  29.             print('账号不存在')
复制代码


小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-26 21:19

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表