day11 本日作业+周末作业
一、今日作业
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("非法输入")
day11 本日作业+周末作业的更多相关文章
- day16 本日作业+周末作业
目录 1.编写计数器功能,要求调用一次在原有的基础上加1 2.周末作业 1.编写计数器功能,要求调用一次在原有的基础上加1 def func(): x=0 def counter(): nonloca ...
- day03 作业 and 周末作业
请输出 name 变量对应的值中 "e" 所在索引位置? # name = "leX leNb"# num = 0# while num < len(na ...
- [福大软工] Z班 团队作业——系统设计 作业成绩
团队作业--系统设计 作业链接 http://www.cnblogs.com/easteast/p/7709763.html 作业情况 这次作业大家完成度都很高,大家的团队分工,任务布置都安排得很到位 ...
- 如何使用git 提交作业 收作业
如何使用git 提交作业 收作业 方法论: 今天就来用一个通俗易懂的自然模型来解释Git的commit,pull和push.不过,我们首先要理解两个名词,remote,local. remote,翻译 ...
- day3(第一周)周末作业
1.创建字符串变量的三种写法及其区别# 代码:单引号 ''# 双引号 ""# 多引号 ''' '''# 区别:单引号和双引号没有任何区别,一般用于单行字符:多行字符用多引号.## ...
- 10月20日MySQL数据库作业解析
设有一数据库,包括四个表:学生表(Student).课程表(Course).成绩表(Score)以及教师信息表(Teacher).四个表的结构分别如表1-1的表(一)~表(四)所示,数据如表1-2的表 ...
- Linux 第30天: (08月5日) 练习和作业
变量脚本 1.编写脚本/root/bin/systeminfo.sh,显示当前主机系统信息,包括主机名,IPv4地址,操作系统版本,内核版本,CPU型号,内存大小,硬盘大小 server_ip=`if ...
- xv6的作业翻译——作业1 - shell和系统调用
Xv6的lecture LEC 1 Operating systems L1: O/S overview L1:O/S概述 * 6.828 goals 6.828的目标 Understan ...
- C语言第四次作业-嵌套作业
一.PTA实验作业 题目1:7-4 换硬币 1. 本题PTA提交列表 2.设计思路 第一:定义三个整型变量f,t,o,分别代表五分,两分,一分的数量 第二:输入待换金额x 第三:令f=x/5;t=x/ ...
随机推荐
- fopen函数中的mode参数
fopen FILE * fopen ( const char * filename, const char * mode ); 其中,参数mode可取以下值: "r"read: ...
- Lombok介绍和使用
1 Lombok背景介绍 官方介绍如下: Project Lombok makes java a spicier language by adding 'handlers' that know how ...
- TensorFlow从0到1之TensorBoard可视化数据流图(8)
TensorFlow 使用 TensorBoard 来提供计算图形的图形图像.这使得理解.调试和优化复杂的神经网络程序变得很方便.TensorBoard 也可以提供有关网络执行的量化指标.它读取 Te ...
- 授权函数-web_set_certificate_ex
设置证书和密钥文件属性. int web_set_certificate_ex(const char * option_list,LAST); 该函数与Loadrunner 录制设置属性中的Recor ...
- C++ Primer Plus(一)
完整阅读C++ Primer Plus 系统重新学习C++语言部分,记录重要但易被忽略的,关键但易被遗忘的. 预备 1.C++相对于C增加了最关键的两项,面向对象和范型编程. 处理数据 2.对于变量明 ...
- java中int和Integer的区别?为什么有了int还要有设计Integer?
参考https://blog.csdn.net/chenliguan/article/details/53888018 https://blog.csdn.net/myme95/article/det ...
- 10.实战交付一套dubbo微服务到k8s集群(3)之二进制安装Maven
maven官网:https://maven.apache.org/ maven二进制下载连接:https://archive.apache.org/dist/maven/maven-3/3.6.1/b ...
- 容器技术之Docker-swarm
前文我聊到了docker machine的简单使用和基本原理的说明,回顾请参考https://www.cnblogs.com/qiuhom-1874/p/13160915.html:今天我们来聊一聊d ...
- 使用IntelliJ/Eclipse生成类图
IntelliJ可以安装一个免费的pugins - Code Iris. PlantUML 在Eclipse中 - ObjectAidPapyrusEclipse Modeling Tools 查看原 ...
- 警告Establishing SSL connection without server's identity verification is not recommended
[本文版权归微信公众号"代码艺术"(ID:onblog)所有,若是转载请务必保留本段原创声明,违者必究.若是文章有不足之处,欢迎关注微信公众号私信与我进行交流!] SpringBo ...