zoukankan      html  css  js  c++  java
  • 01_python基础练习_01login

    README:

    How to use it:
    There is a file with username and password named 'username.txt' in directory 'login'.
    When user inputs username and password, the program will verify it. If they are wrong, user can try again.
    Remember user only have three chances, then the wrong username will be writen in the file named 'name_locked.txt'.
    If the username user inputs is in 'name_locked.txt', user has no chance to try again!

     1 # Author:Zhang Yide
     2 # coding:utf-8
     3 
     4 count = 0
     5 done = False
     6 lock = False
     7 _name = None
     8 
     9 while count < 3:
    10     _name = input('Please input username:')
    11     _password = input('Please input password:')
    12     _namepw = _name + ': ' + _password + '
    '
    13 
    14     #判断_namepw是否在name_locked.txt中
    15     f_lock = open('name_locked.txt')
    16     for line in f_lock.readlines():
    17         if line == _name + '
    ':
    18             print('{name} has been locked!'.format(name=_name))
    19             f_lock.close()
    20             lock = True
    21             f_lock.close()
    22             break
    23         else:
    24             continue
    25 
    26     # 判断_namepw是否在username.txt中
    27     f_username = open('username.txt')
    28     for line in f_username.readlines():
    29         if line == _namepw:
    30             print('Welcome {name}!'.format(name=_name))
    31             done = True
    32             f_username.close()
    33             break
    34         else:
    35             continue
    36 
    37     #如果不在username.txt文件中,提示错误。
    38     if done == False and lock == False:
    39         print('Username or password is wrong! Try again!')
    40         count += 1
    41         f_username.close()
    42     else:
    43         break
    44 #现已被锁定且之前未被锁定,则写入lock.txt.
    45 if done == False and lock ==False :
    46     print('The username {name} has been locked'.format(name=_name))
    47     with open('name_locked.txt', 'a') as f_lock:
    48         f_lock.write('{name}
    '.format(name = _name))
    49 else:
    50     pass
  • 相关阅读:
    syslog(),closelog()与openlog()--日志操作函数 (1)
    C语言之strrchr函数
    HTTP 报文
    Apache Hive 建表操作的简单描述
    Apache Hive 简介及安装
    Hadoop之MapReduce(二)序列化,排序及分区
    Hadoop之MapReduce(一)简介及简单案例
    Hadoop之HDFS(三)HDFS的JAVA API操作
    Hadoop之HDFS(二)HDFS基本原理
    Hadoop之HDFS(一)HDFS入门及基本Shell命令操作
  • 原文地址:https://www.cnblogs.com/zhangyide/p/7890446.html
Copyright © 2011-2022 走看看