第一周作业:

作业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-模拟登录的更多相关文章

  1. Python课程第一天作业

    一.第一题:简述编译型与解释型语言的区别,且分别列出你知道的哪些语言属于编译型,哪些属于解释型? 计算机是不能理解高级语言的,更不能直接执行高级语言,它只能直接理解机器语言,所以使用任何高级语言编写的 ...

  2. Python爬虫初学(三)—— 模拟登录知乎

    模拟登录知乎 这几天在研究模拟登录, 以知乎 - 与世界分享你的知识.经验和见解为例.实现过程遇到不少疑问,借鉴了知乎xchaoinfo的代码,万分感激! 知乎登录分为邮箱登录和手机登录两种方式,通过 ...

  3. Python 3.3.3 使用requests模拟登录网站

    在模拟登录上,requests确实比python标准库中的相关模块更加简洁. 假设你需要去爬一组页面(targetUrls),而这些页面要登录才能进行访问.那么requests能够提供一种相当简单的语 ...

  4. python爬虫【实战篇】模拟登录人人网

    requests 提供了一个叫做session类,来实现客户端和服务端的会话保持 使用方法 1.实例化一个session对象 2.让session发送get或者post请求 session = req ...

  5. python入门第一天作业。讲师写的代码。

    #!/uer/bin/env python # _*_ coding: utf-8 _*_ import sys retry_limit = 3 retry_count = 0 account_fil ...

  6. Python课程第二天作业

     一.统计字符串格式 要求: # 1.统计元组中所有数据属于字符串的个数,提示: isinstance() # 数据: t1 = (1, 2, '3', '4', 5, '6') # 结果: 3 代码 ...

  7. Python课程第八天作业

    第一题: 1.自定义一个 Fruit 类:该类有一个 类属性: identify:值为"水果",有两个对象属性: name,price:值由实例化对象时赋值,一个类方法: get_ ...

  8. python课程第一天笔记-la

    http://www.cnblogs.com/onda/   ----------------------20170423 一:Cpython  pypy 区别 等;Cpython 是一行一行解释, ...

  9. python3作业:模拟登录

    __author__ = "bin007" customer = {}#存储用户信息#处理用户信息文件try: with open('login.txt','r',encoding ...

随机推荐

  1. foreach遍历原理(一)

    前言 要使用foreach的遍历的类首先要满足的条件 1. 类要实现公共方法 public IEnumerator GetEnumerator(){},还可以继承IEnumerable接口来实现这个方 ...

  2. zepto源码研究 - zepto.js - 6(模板方法)

    width  height  模板方法   读写width/height ['width', 'height'].forEach(function(dimension){ //将width,hegih ...

  3. uva 12207 - That is Your Queue

    #include <cstdio> #include <iostream> #include <deque> using namespace std; int ma ...

  4. 使用github创建博客

    本文主要介绍以下几个内容: 1.使用githbu创建自己的博客 2.将博客域名映射到自己的域名 3.如果写博客   一.使用github创建自己的博客 具体可参考https://pages.githu ...

  5. 百度文本编辑器 Ueditor for net 使用七牛存储附件的实现

    百度编辑器功能强大,确实好用,可惜附件使用本地存储,如果网站的用户量巨大,则会使得网站目录变得非常庞大,而且文件不易于管理,七牛云存储在附件存储方面下了不少功夫,用起来感觉不错,要是将ueditor ...

  6. 用javascript预加载图片、css、js的方法研究

    预加载的好处可以让网页更快的呈现给用户,缺点就是可能会增加无用的请求(但图片.css.js这些静态文件可以被缓存),如果用户访问的页面里面的css.js.图片被预加载了,用户打开页面的速度会快很多,提 ...

  7. discuz php判断是手机访问还是电脑访问网站

    首先在模块处填入代码: //手机网页跳转 //如果检测到访问的浏览器为下列一个指定的移动浏览器 则返回true function is_mobile(){ $regex_match="/(n ...

  8. How to install ffmpeg,mp4box,mplayer,mencoder,flvtool2,ffmpeg-php on centos

    1. Enable RPM Fusion yum repository The CentOS rpm packages of ffmpeg, mplayer, mencoder and MP4Box ...

  9. 机器人操作系统ROS | 简介篇

    同样,从个人微信公众号Nao(ID:qRobotics)搬运. 前言 先放一个ROS Industrial一周年剪辑视频. ROS已经发布八周年了,在国外科研机构中非常受欢迎.目前,以美国西南研究院为 ...

  10. javascript scroll事件

    http://developer.51cto.com/art/201107/277994.htm onscroll事件 window.onscroll|| document.onscroll var ...