01_python basic exercise _ 01 login, 01_python_01login

Source: Internet
Author: User

01_python basic exercise _ 01 login, 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 +' \ n' 13 14 character _ namepw in name_locked.txt 15 f_lock = open('name_locked.txt ') 16 for line in f_lock.readlines (): 17 if line = _ name +' \ N ': 18 print ('{name} has Been locked! '. Format (name = _ name) 19 f_lock.close () 20 lock = True21 f_lock.close () 22 break23 else: 24 continue25 26 # pai_namepw.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 = True32 f_username.close () 33 break34 else: 35 continue36 37 rows if the username.txt file is being uploaded, an error is prompted. 38 if done = False and lock = False: 39 print ('username or password is wrong! Try again! ') 40 count + = 141 f_username.close () 42 else: 43 break44 cursor is locked and is written to 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} \ n '. format (name = _ name) 49 else: 50 pass

 

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.