【python入门】简单实现注册、登陆、删除账户

作为一个迷惘的金融狗,曾关注一些实习要求python,开始了解这门语言。

后来发现在金融这一领域的实习要求中,要求python而不是各种证书&实习经历的仅仅是占少数。

这条路,漫漫长而又艰险。一定会遇见光,但是很可能不是属于金融背景的python程序员。也许是IT、数理背景出身的具备python编程能力的懂得基础金融知识的人吧。

金融金融,当今也许皇冠不在,但是仍是不错的选择。

程序员之路

只求不脱发&性别不歧视。

若是个男生倒不介意了

——————以下为主要内容——————

本次代码实现的是 注册、登陆以及删除账户的功能。

如果有更简洁、高效的写法,欢迎和我交流呀~
# Author:王帅帅的升级打怪之路
'''
登陆界面可实现功能:
注册(可检测是否重名);
登陆(输错三次锁定);
注销账户(输错三次锁定)。
可实现注册后接着登陆或者注销账户。
'''

# 储存用户名和密码的列表。
usernameANDpassword_list = [["mac", "abc123"], ["apple", "6789bnm"], ["pencil", "123456"]]

UserChoice = input("Enter register, login or delete.")
Judgement = True
while Judgement:
    if UserChoice == "register":
        flag1 = True
        while flag1:
            username = input("Register:input a username.")
            keyV = 0  # 用于判断注册输入的用户名是否已存在。
            for i in usernameANDpassword_list:
                if username == i[0]:
                    keyV += 1
                else:
                    keyV += 0
            if keyV != 0:
                print("The name already exists, please try another one.")
            else:
                password = input("Register:input your password.")
                usernameANDpassword_list.append([username, password])
                print("you've already registered.")
                flag1 = False  # 注册成功之后跳出while循环
                Continue = input("Please input N to exist or Y to continue other operations.")
                if Continue == "N":
                    Judgement = False
                else:
                    UserChoice = input("Enter register, login or delete.")

    elif UserChoice == "login":
            count = 0
            keyV = 0
            while count < 3:
                username = input("Login:input your username.")
                password = input("Login:input your password.")
                for i in usernameANDpassword_list:
                    if username == i[0] and password == i[1]:
                        keyV += 1
                    else:
                        keyV += 0
                if keyV != 0:
                    print("you've login!!!")
                    Continue = input("Please input N to exist or Y to continue login or delete.")
                    if Continue == "N":
                        Judgement = False
                    else:
                        UserChoice = input("Enter register, login or delete.")
                    break  # 退出while循环
                else:
                    print("your username or password is wrong.")
                    count += 1
                if count == 3:
                    print("you've tried too many times.Your account has been locked.")
                    Judgement = False
    elif UserChoice == "delete":
        count = 0
        keyV = 0
        while count < 3:
            username = input("Delete:input your username.")
            password = input("Delete:input your password.")
            for i in usernameANDpassword_list:
                if username == i[0] and password == i[1]:
                    keyV += 1
                else:
                    keyV += 0
            if keyV != 0:
                delete_confirm = input("Are you sure? \
                Please input Y to delete or N to cancel.")
                if delete_confirm == "Y":
                    index = usernameANDpassword_list.index([username, password])
                    del usernameANDpassword_list[index]
                    print("your account has been deleted.")
                    Continue = input("Please input N to exist or Y to continue login or delete.")
                    if Continue == "N":
                        Judgement = False
                    else:
                        UserChoice = input("Enter register, login or delete.")
                    break
                    # usernameANDpassword_list.pop(index) 另一种删除方法。
                else:
                    print("you cancel this operation.")
                    Continue = input("Please input N to exist or Y to continue login or delete.")
                    if Continue == "N":
                        Judgement = False
                    else:
                        UserChoice = input("Enter register, login or delete.")
                    break
            else:
                count += 1
            if count == 3:
                print("you've tried too many times.")
                Continue = input("Please input N to exist or Y to continue login or delete.")
                if Continue == "N":
                    Judgement = False
                else:
                    UserChoice = input("Enter register, login or delete.")
            else:
                print("the username or password is wrong or unavailable.")

    else:
        print("you didn't correctly choose a function.")
        Judgement = False


猜你喜欢

转载自www.cnblogs.com/wyy66/p/10122763.html
今日推荐