Assignments for the first week of Python learning-user simulated login, python --

Source: Internet
Author: User

Assignments for the first week of Python learning-user simulated login, python --

Job Requirements:
(1) The user enters the account password for login
(2) Save User information in the file
(3) The user is locked after three wrong passwords are entered.

1 #! /Usr/bin/env python 2 # _ * _ conding: UTF-8 _ * _ 3 4 username = "gx" # login name 5 password = "123" # password 6 count = 0 7 8 p = open ("login.txt", "r ") 9 file_list = p. readlines () 10 p. close () 11 lock = [] # blacklist 12 13 name = input ("Enter username:") 14 for I in file_list: 15 lock. append (I) 16 if name in lock: 17 print ("The user has been locked, please contact the admin") # judge that The name is not in the blacklist 18 else: 19 if name = username: 20 while Count <:21 pwd = input ("Enter passwod:") 22 if name = username and pwd = password: 23 print ("Welcome % s! "% Name) 24 break # enter the correct name and password to log on and end 25 else: 26 print (" Sorry password is incorrect please re-enter ") 27 count ++ = 128 else: 29 print ("Paswword error three times, has been locked, please contact the admin") 30 p = open ("login.txt", "w + ") 31 n = ["% s" % name] 32 p. writelines (n) 33 p. close () 34 else: 35 print ("Username does not exist, please re-enter ")
View Code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.