Python 模拟三次用户登录,登录失败锁定账号并写入文件

简介:

 登录要求:

   1、用户输入登录账号 、密码,登录成功显示欢迎用户登录界面

   2、 用户可以尝试三次登录,三次登录失败后,将锁定用户,并输出到新的文件当中。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
count  =  0
while  count <  3  :
     file1  =  open ( "accounts.txt" "r" )
     data1  =  file1.read().strip().split()
     username  =  input ( "Please input your username>>>> " )
     password  =  input ( "Please input your password>>>> " )
     if  username  = =  data1[ 0 and  password  = =  data1[ 1 ]:
         print ( "welcom to %s login"  % username)
         break ;
     elif  username  = =  data1[ 2 and  password  = =  data1[ 3 ]:
         print ( "welcom to %s login"  %  username)
         break ;
     elif  username  = =  data1[ 4 and  password  = =  data1[ 5 ]:
         print ( "welcom to %s login"  %  username)
         break ;
     else :
         print ( "user  %s login is failure please try again"  %  username)
     count  =  count  +  1
else :
     file2  =  open ( "lock_userlist.txt" "w" )
     file2.write(username)
     print ( "you have try 3 times your %s is locked\n"  % username)

    accounts.txt 

  image.png


测试:登录成功 

image.png


测试 :登录失败

image.png

image.png



本文转自 水滴石川1 51CTO博客,原文链接:http://blog.51cto.com/sdsca/2051801,如需转载请自行联系原作者

相关文章
|
17天前
|
Python
【python】python跨文件使用全局变量
【python】python跨文件使用全局变量
|
25天前
|
监控 数据处理 索引
使用Python批量实现文件夹下所有Excel文件的第二张表合并
使用Python和pandas批量合并文件夹中所有Excel文件的第二张表,通过os库遍历文件,pandas的read_excel读取表,concat函数合并数据。主要步骤包括:1) 遍历获取Excel文件,2) 读取第二张表,3) 合并所有表格,最后将结果保存为新的Excel文件。注意文件路径、表格结构一致性及异常处理。可扩展为动态指定合并表、优化性能、日志记录等功能。适合数据处理初学者提升自动化处理技能。
21 1
|
30天前
|
存储 并行计算 Java
Python读取.nc文件的方法与技术详解
本文介绍了Python中读取.nc(NetCDF)文件的两种方法:使用netCDF4和xarray库。netCDF4库通过`Dataset`函数打开文件,`variables`属性获取变量,再通过字典键读取数据。xarray库利用`open_dataset`打开文件,直接通过变量名访问数据。文中还涉及性能优化,如分块读取、使用Dask进行并行计算以及仅加载所需变量。注意文件路径、变量命名和数据类型,读取后记得关闭文件(netCDF4需显式关闭)。随着科学数据的增长,掌握高效处理.nc文件的技能至关重要。
108 0
|
1月前
|
存储 Python
Python中如何读取和写入文件?请提供代码示例。
【2月更文挑战第26天】【2月更文挑战第87篇】Python中如何读取和写入文件?请提供代码示例。
|
1月前
|
Python
python中文件和异常处理方法(二)
python中文件和异常处理方法(二)
13 0
|
1月前
|
Python
python中文件和异常处理方法(一)
python中文件和异常处理方法(一)
29 0
|
1月前
|
Python
python中文件和异常处理方法(三)
python中文件和异常处理方法(三)
19 0
|
17天前
|
C++ Python
【C++/Python】C++调用python文件
【C++/Python】C++调用python文件
|
17天前
|
JSON 数据处理 数据格式
Python中的文件读写操作详解
【4月更文挑战第2天】在Python中,文件读写操作是数据处理和程序开发的重要部分。通过文件,我们可以将信息持久化地保存在磁盘上,并在需要时读取和使用这些数据。Python提供了丰富的内置函数和模块,使得文件读写变得简单而高效。本文将详细介绍Python中文件读写的基本操作和常用方法。
|
29天前
|
开发者 Python
Python语言的文件及目录访问
Python语言的文件及目录访问

热门文章

最新文章