Two weeks weekend work

Two: Weekend integrated operations:

2.1: Writing User Interface login

1, enter the account password to complete the verification, validation output "login success" after the adoption of

inp_name = input('输入账号: ').strip()
inp_pwd = input('输入密码: ').strip()
if inp_name == 'tom' and inp_pwd == '111':
    print('登录成功')
else:
    print('账号或密码不正确')

2, different users can log in

user_info = {'tom': '111', 'jack': '222', 'marry': '333'}
inp_name = input('输入账号: ').strip()
inp_pwd = input('输入密码: ').strip()
if inp_name in user_info and inp_pwd == user_info[inp_name]:
    print('登录成功')
else:
    print('账号或密码不正确')

3, unsuccessful attempts to enter the same account locked (Note: locking the user into a file, so as to ensure the program is closed, the user still locked)

all_user_info = {
    'tom': 111,
    'jarry': 222,
    'jack': 333
}
tage = True
number = 0
while tage:
    username = input('请输入用户名: ')
    if username in all_user_info:
        print('当前用户为:{}'.format(username))
        with open('a.txt', mode='rt', encoding='utf_8') as f1:
            res = f1.read()
            x = res.split()
            if username in x:
                print('当前用户也被锁定')
            else:
                while number < 3:
                    password = input('输入密码: ')
                    if password == all_user_info.get(username):
                        pirnt('登录成功')
                        tage = False
                        break
                    else:
                        print('密码输入错误!')
                        number += 1
                        if number == 3:
                            number = 0
                            print('当前用户输错三次已被锁定')
                            with open('a.txt', mode='at', encoding='utf_8') as f1:
                                f1.write('{}:'.format(username))
                            break
    else:
        print('用户不存在')

2.2: After programming implement user registration, you can log

1、

tage = True
while tage:
    msg = """
    0 退出
    1 登录
    2 注册
    """
    print(msg)
    cmd = input('请输入命令编号>>: ').strip()
    if not cmd.isdigit():
        print('必须输入命令编号的数字,傻叉')
        continue

    if cmd == '0':
        break
    elif cmd == '1':
        with open('a.txt', mode='rt', encoding='utf_8') as f1:
            for i in range(3):
                inp_name = input('输入账号: ').strip()
                inp_password = input('输入密码: ').strip()
                for line in f1:
                    username, password = line.strip().split(':')
                    if inp_name == username and inp_password == password:
                        print('登录成功')
                        tage = False
                        break
                break
            else:
                print('输错三次,退出')
                tage = False
    elif cmd == '2':
        with open('a.txt', mode='at', encoding='utf_8') as f2:
            inp_name = input('输入账号: ').strip()
            inp_password = input('输入密码: ').strip()
            f2.write('{}:{}\n'.format(inp_name, inp_password))
    else:
        print('输入的命令不存在')

2、

Two: Weekend integrated operations:

2.1: Writing User Interface login

1, enter the account password to complete the verification, validation output "login success" after the adoption of

inp_name = input('输入账号: ').strip()
inp_pwd = input('输入密码: ').strip()
if inp_name == 'tom' and inp_pwd == '111':
    print('登录成功')
else:
    print('账号或密码不正确')

2, different users can log in

user_info = {'tom': '111', 'jack': '222', 'marry': '333'}
inp_name = input('输入账号: ').strip()
inp_pwd = input('输入密码: ').strip()
if inp_name in user_info and inp_pwd == user_info[inp_name]:
    print('登录成功')
else:
    print('账号或密码不正确')

3, unsuccessful attempts to enter the same account locked (Note: locking the user into a file, so as to ensure the program is closed, the user still locked)

all_user_info = {
    'tom': 111,
    'jarry': 222,
    'jack': 333
}
tage = True
number = 0
while tage:
    username = input('请输入用户名: ')
    if username in all_user_info:
        print('当前用户为:{}'.format(username))
        with open('a.txt', mode='rt', encoding='utf_8') as f1:
            res = f1.read()
            x = res.split()
            if username in x:
                print('当前用户也被锁定')
            else:
                while number < 3:
                    password = input('输入密码: ')
                    if password == all_user_info.get(username):
                        pirnt('登录成功')
                        tage = False
                        break
                    else:
                        print('密码输入错误!')
                        number += 1
                        if number == 3:
                            number = 0
                            print('当前用户输错三次已被锁定')
                            with open('a.txt', mode='at', encoding='utf_8') as f1:
                                f1.write('{}:'.format(username))
                            break
    else:
        print('用户不存在')

2.2: After programming implement user registration, you can log

1、

tage = True
while tage:
    msg = """
    0 退出
    1 登录
    2 注册
    """
    print(msg)
    cmd = input('请输入命令编号>>: ').strip()
    if not cmd.isdigit():
        print('必须输入命令编号的数字,傻叉')
        continue

    if cmd == '0':
        break
    elif cmd == '1':
        with open('a.txt', mode='rt', encoding='utf_8') as f1:
            for i in range(3):
                inp_name = input('输入账号: ').strip()
                inp_password = input('输入密码: ').strip()
                for line in f1:
                    username, password = line.strip().split(':')
                    if inp_name == username and inp_password == password:
                        print('登录成功')
                        tage = False
                        break
                break
            else:
                print('输错三次,退出')
                tage = False
    elif cmd == '2':
        with open('a.txt', mode='at', encoding='utf_8') as f2:
            inp_name = input('输入账号: ').strip()
            inp_password = input('输入密码: ').strip()
            f2.write('{}:{}\n'.format(inp_name, inp_password))
    else:
        print('输入的命令不存在')

2、

Guess you like

Origin www.cnblogs.com/zhangtieshan/p/12501173.html