Path to python-basics-Job 1 Write logon interface, python Basics

Source: Internet
Author: User

Path to python-basics-Job 1 Write logon interface, python Basics

Job Requirements:

① Enter the user name and password

② Display the welcome information after successful authentication

③ Lock after three wrong attempts

 

Flowchart:

The picture is not clear, please move your feet to the http://pan.baidu.com/s/1pKqlXQr

#! /Usr/bin/env python #-*-coding: UTF-8-*-# file_name: user_login.pylock = 0lock_value = 'no' lock _ dict = {} user_dict = {} f1 = open('lock.txt ', 'r +') f2 = open('user.txt ', 'R ') for I in f1.readlines (): user, number = I. strip (). split () lock_dict [user] = numberfor I in f2.readlines (): user, passwd = I. strip (). split () user_dict [user] = passwdwhile lock <3: # enter the cyclic username = input ("Enter the user name:") pass Wd = input ("Enter Password:") if lock_dict.get (username): # username exists in lock.txt if int (lock_dict.get (username)> = 3: print ('account locked. Please enter it again! ') Lock + = 1 continue if user_dict.get (username): # if passwd = user_dict.get (username) exists in user_dict: # print if the password is correct ('login successful ') break else: # incorrect password if lock_dict.get (username): # username in lock_dict [username] = int (lock_dict [username]) + 1 lock_value = 'yes' else: # username does not exist in lock_dict [username] = 1 lock_value = 'yes' else: # username does not exist in user_dict lock_value = 'Yes 'If lock_value = 'yes': print ('account Password error, please enter 'Again) lock + = 1 continueelse: # print more than 3 times ('Sorry, the number of inputs has exceeded the upper limit! ') # Clear lock.txt f1.seek (0) f1.truncate (0) for I in lock_dict: username = I number = lock_dict [I] f1.write ('% s \ t % s \ n' % (username, number) f1.close () f2.close ()

 

Auxiliary file:

① User.txt zhangcong 123 admin 123 zhangsan 123 ② lock.txt is empty

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.