python 自学day1(关于if和file的应用练习)
2024-09-25 11:25:34
1.编写简单的登陆接口
#判断用户信息
#用户输入错误后锁定账号
流程图:
代码:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
document1 = open('userinfo.txt', 'r')
document2 = open('falseuser.tex', 'w+')
document3 = open('lock.txt', 'w+')
i = 1
n = 1
while i < 4 and n < 4:
username = input('username:')
password = input('password:')
str1 = document1.read()
h = len(username)
if str1.find(username) >= 0 and document2.read().find(username) == -1:
if str1.find(password, (str1.find(username)+h+1), len(password)):
print('welcome to our web!')
break
else:
document2.write(username)
i += 1
else:
if document2.read().find(username) >= 0:
if str1.find(password, (str1.find(username)+h+1), len(password)) and document3.read().find(username) == -1:
print('welcome to our web!')
elif document3.read().find(username) != -1:
print('you have try 3 times')
break
else:
i += 1
print('confirm password')
else:
print('plese input right username')
n += 1
while i == 3:
document3.write(username)
document3.close()
document2.close()
document1.close()
pycharm python3.7版本可用。
最新文章
- Linux环境变量设置
- js封装的三级联动菜单(使用时只需要一行js代码)
- window.location.href无法跳转的解决办法
- 【javascript实例】 具有立体效果的图片浏览器
- html5 datalist自动完成
- Word或者Excel中怎么把 ";空格"; 替换成 ";换行 ";
- 【Linux】Linux字体颜色
- 《JavaScript DOM编程艺术》
- C++编写Config类读取配置文件
- Objective-C学习篇09—NSNumber与笑笑语法
- 所需的防伪表单字段“__RequestVerificationToken”不存在
- 201521123003《Java程序设计》第10周学习笔记
- [转载] JaCoCo:分析单元测试覆盖率的利器
- Android开发学习之路--UI之基本布局
- [Android][Recovery] Recovery下找不到sdcard路径
- input的三个属性autocomplete、autocapitalize和autocorrect
- 52ABP模板 ASP.Net Core 与 Angular的开源实例项目
- codeforces546C
- 20165237 预备作业3 Linux安装及学习
- 进度条(progress_bar)
热门文章
- [WEB安全]IIS-PUT漏洞
- Spring框架中不同类型的事件
- cannot load from mysql.proc. the table is probably corrupted 解决办法
- case设计及验证:入口+页面+展示
- C++ STL介绍——简介
- selinux 开启和关闭
- ASP.NET MVC传递Model到视图的多种方式之通用方式的使用
- redis json 降低性能 使用 hash
- mybatis 的 <;![CDATA[ ]]>; 标签作用
- Spring走向注解驱动编程