一、今日作业

1、编写文件copy工具

with open("a.txt",mode="r",encoding="utf-8") as f1 ,open("b.txt",mode="w",encoding="utf-8") as f2:
f2.write(f1.read())

2、编写登录程序,账号密码来自于文件

user_inp = input("请输入用户名:")
pwd_inp = input("请输入密码:")
with open("a.txt",mode="r",encoding="utf-8") as f :
for line in f:
username,password = line.strip().split(":")
if username == user_inp and password == pwd_inp:
print("登录成功")
break
else:
print("账号或秘密错误")

3、编写注册程序,账号密码来存入文件

username = input("请输入账号:").strip()
password = input("请输入密码:")
with open("b.txt","a",encoding="utf-8") as f :
f.write("\n{}:{}".format(username,password))

二、周末综合作业:

1、编写用户登录接口

1、输入账号密码完成验证,验证通过后输出"登录成功"

2、可以登录不同的用户

3、同一账号输错三次锁定,(提示:锁定的用户存入文件中,这样才能保证程序关闭后,该用户仍然被锁定)

import os
count = 0
tag = True
list1 = []
while tag:
username = input("请输入用户名:")
if os.path.exists("locked\{}".format(username)):
print("用户被锁定")
count=0
break
password = input("请输入密码:")
with open("a.txt",mode="r",encoding="utf-8") as f :
for line in f :
user,pwd = line.strip().split(":")
if username == user and password == pwd:
print("登录成功")
tag = False
break
else:
if list1.count(username) ==2:
with open("locked\{}".format(username),"w") as f :
print("错误3次该用户被锁定")
else:
list1.append(username)
print(list1.count(username))
print("登录失败")

2、编写程序实现用户注册后,可以登录

import os
list2=[]
list1=["1","2","3"]
while True:
print('''
1.注册
2.登录
3.退出
''')
cmd = input("cmd>")
tag=True
if cmd == list1[0]:
username = input("请输入你要注册的账号:")
password = input("请输入你要注册的密码:")
with open("a.txt","a",encoding="utf-8") as f :
f.write(f"{username}:{password}\n")
elif cmd == list1[1]:
while tag:
use_inp = input("请输入你的用户名:")
if os.path.exists(f"locked/{use_inp}"):
print("账号被锁定")
tag = False
break
else:
pwd_inp = input("请输入你的密码:")
with open("a.txt","r",encoding="utf-8") as f :
for line in f :
username,password=line.strip().split(":")
if use_inp==username and password==pwd_inp:
print("登录成功")
tag = False
break
else:
if list2.count(use_inp) == 2:
with open(f"locked/{use_inp}","w",encoding="utf-8") :
pass
print("账号被锁定")
break
else:
print("输入错误")
list2.append(use_inp)
print(list2.count(use_inp)) elif cmd == list1[2]:
break
else:
print("非法输入")

最新文章

  1. 前端构建工具的用法—grunt、gulp、browserify、webpack
  2. Android网络操作的几种方法
  3. Bringing up interface eth0: Error:Connection activation failed:Device not managed by NetworkManager
  4. groovy-位运算
  5. java中直接打印对象
  6. BZOJ 2038
  7. JAVA:IO流——File类
  8. Android listview的item设定高度
  9. ioctl用法详解 (网络)
  10. MYSQLl防注入
  11. sql用户权限
  12. nodejs 记入
  13. svn恢复到之前某个版本号
  14. perl 执行mysql select 返回多条记录
  15. POJ 3070 Fibonacci(矩阵高速功率)
  16. spring实现数据库读写分离
  17. Mybatis基本用法--上
  18. Jerry 2017年的五一小长假:8种经典排序算法的ABAP实现
  19. 小白的Python之路_day1
  20. ALM 中查看某个 test 的更改 history 历史

热门文章

  1. 由软件构造引申的OOP与POP的心得体会
  2. Android学习笔记点击事件和触摸事件的区别
  3. 如何 SSH 到 Linux 服务器里的特定目录及执行命令?
  4. cb02a_c++_数据结构_顺序容器_STL_list类_双向链表
  5. C++_继承
  6. Asp.Net Core入门之静态文件
  7. 效率思维模式与Zombie Scrum
  8. js中.bind()和.call()用法讲解
  9. ps学习。
  10. Flutter学习笔记(38)--自定义控件之组合控件