python课程第一天作业1-模拟登录
第一周作业:
作业1:编写登陆接口
- 输入用户名密码
- 认证成功后显示欢迎信息
- 输错三次后锁定
流程图:

代码:后来修改过一次:
#!/usr/bin/env python
# -*-conding:utf-8-**
# __Author__:'liudong'
#!/usr/bin/env python
# -*-coding:utf-8-*-
# __author__="Life"
print('You have three times to login,otherwise your account will be locked!')
for i in range(3):
username = input('Please input your username:')
lock_file = open('account_lock.txt', 'r')
lock_list = lock_file.readlines() # 已经被锁定用户清单文件
for lock_line in lock_list: #判断用户输入的名字是否已经锁定(在锁定的文件列表中)
lock_line = lock_line.strip('\n')
if username == lock_line:
print('Your account is locked!')
lock_file.close()
exit()
user_account=open('user_account.txt','r')
user_account_list=user_account.readlines()
#print(user_account_list)
for user in user_account_list:
(user_infile,password_infile)=user.strip('\n').split()
if username == user_infile:
#print(user_infile)
j = 0
while j < 3:
password = input('Please input your password:')
if password == password_infile:
print('login successed!')
user_account.close()
lock_file.close()
exit()
else:
print('Invalid username or password...')
print('this is the %d time(s)' % (j + 1))
j+=1
else:
lock_file = open('account_lock.txt', 'w')
lock_file.write(username + '\n') #锁定用记名写入锁定文件
print('Your account is locked! Please,contact adminstrator to unlock your account!') exit()
else:
print('user %s is not exists,please input again:') lock_file.close()
user_account.close()
python课程第一天作业1-模拟登录的更多相关文章
- Python课程第一天作业
一.第一题:简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释型? 计算机是不能理解高级语言的,更不能直接执行高级语言,它只能直接理解机器语言,所以使用任何高级语言编写的 ...
- Python爬虫初学(三)—— 模拟登录知乎
模拟登录知乎 这几天在研究模拟登录, 以知乎 - 与世界分享你的知识.经验和见解为例.实现过程遇到不少疑问,借鉴了知乎xchaoinfo的代码,万分感激! 知乎登录分为邮箱登录和手机登录两种方式,通过 ...
- Python 3.3.3 使用requests模拟登录网站
在模拟登录上,requests确实比python标准库中的相关模块更加简洁. 假设你需要去爬一组页面(targetUrls),而这些页面要登录才能进行访问.那么requests能够提供一种相当简单的语 ...
- python爬虫【实战篇】模拟登录人人网
requests 提供了一个叫做session类,来实现客户端和服务端的会话保持 使用方法 1.实例化一个session对象 2.让session发送get或者post请求 session = req ...
- python入门第一天作业。讲师写的代码。
#!/uer/bin/env python # _*_ coding: utf-8 _*_ import sys retry_limit = 3 retry_count = 0 account_fil ...
- Python课程第二天作业
一.统计字符串格式 要求: # 1.统计元组中所有数据属于字符串的个数,提示: isinstance() # 数据: t1 = (1, 2, '3', '4', 5, '6') # 结果: 3 代码 ...
- Python课程第八天作业
第一题: 1.自定义一个 Fruit 类:该类有一个 类属性: identify:值为"水果",有两个对象属性: name,price:值由实例化对象时赋值,一个类方法: get_ ...
- python课程第一天笔记-la
http://www.cnblogs.com/onda/ ----------------------20170423 一:Cpython pypy 区别 等;Cpython 是一行一行解释, ...
- python3作业:模拟登录
__author__ = "bin007" customer = {}#存储用户信息#处理用户信息文件try: with open('login.txt','r',encoding ...
随机推荐
- mysql存储过程controller的not found造成混乱的解决办法
打草稿 问题:对于select var1 into var2 ,单select的结果为空的时候(空的意思是没有找到数据,不是该值为null) ,会触发controller的not found 当游标 ...
- ASP.NET 文本编辑器使用(CKEditor)与上传图片
CKEditor是什么 CKEidtor是一个在线富文本编辑器,可以将让用户所见即所得的获得编辑在线文本,编辑器或自动将用户编辑的文字格式转换成html代码. 方法一.在ASP.NET工程中添加CKE ...
- impdp/expdp 总结
impdp/expdp 1.创建DIRECTORY create directory dir_dp as '/tmp'; --建议将DIRECTORY 建在 /tmp 表下面,该目录肯定存 ...
- 3.2 GUN as汇编(本文内容大部分引用原文,非原创)
as86汇编仅仅用于编译内核中的boot/bootsect.s引导扇区程序和实模式下的设置程序boot/setup.s.内核中其余所有汇编语言程序(包括C语言产生的汇编程序)均使用gas来编译,并与C ...
- angular启动过程分析
启动过程 步骤一 用自执行函数在代码完成加载后立即执行 function(window, document, undefined) 在window上暴露一个唯一的全局对象angular,Line250 ...
- innerHTML在IE中报错
问题:开发过程中,用到循环往table里面插入tr标签,然后tr里又循环插入td,在其它浏览器都没问题,但是在IE9及以下版本中都报错: google上得到答案:由于我之前不知道错误的原因,在 ...
- PHP 过滤二维数组和三维数组
<?php $arr = [ [1,3,5,7,9], [2,4,6,8,0] ]; $arr2 = [ 'list' => [ [1,3,5,7], [2,4,6,8], [3,2,9, ...
- WordPress插件制作笔记(一)---First Plugins Demo
1->add_action HOOK简单说明: http://codex.wordpress.org/Plugin_API/Action_Reference (参考网址) //在后台页脚位置加 ...
- Visual Studio调试之避免单步跟踪调试模式
Visual Studio调试之避免单步跟踪调试模式 写完Visual Studio调试之断点进阶篇之后,想分享一下我常用的一些调试技巧,后面发现写之前,一些背景知识需要介绍一下. 下面是几篇今年2月 ...
- error on line 1 at column 6: XML declaration allowed only at the start of the document
This page contains the following errors: error on line 1 at column 6: XML declaration allowed only a ...