Python million annual salary of the road - the second week - Analog blog park system

Project analysis:
a. First, the program starts, displays the following contents for users to choose:

1. Login
2. Sign up
3. Go to the article page
4. Enter comments page
5. Go to diary page
6. Go to favorites page
7. cancellation of the account
8. quit the whole program

two. Functions that must be implemented:
1. Registration functional requirements:
. A user name and password to be recorded in the file.
. b User Requirements: You can only contain letters or numbers can not contain special characters and ensure that the user name is unique.
. C password requirements: a length between 6 to 14 characters.

2. Log on functional requirements:
. A user enters a username and password login authentication.
. b After a successful login, you can only access 3--7 options, visit 3:00 If you do not log on or log unsuccessful --7 option does not allow access to jump to login. (Modify global variables)

c. login yet more than three times successfully, quit the whole program.

3. Go to the article page Requirements:
Tips Welcome xx enter the article page. (xx is the user name currently logged in)

4. Enter comments page Requirements:
Tips Welcome xx Enter comments page.

5. Go to diary page Requirements:
Tips Welcome xx to enter the diary page.

6. Go to page collection requirements:
Tips Welcome page xx into the collection.

7. cancellation account requirements:
not to abandon the entire program, but the state has logged into the unregistered status (need to log in again to access the options of 3 to 7).

8. quit the whole program requirements:
is the end of the entire program.

First Edition

s = """
1.请注册
2.请登录
3.进入文章页面
4.进入评论页面
5.进入日记页面
6.进入收藏页面
7.注销账号
8.退出整个程序
"""

print(s)
flag = False
def login():
    """
    登录功能
    :return:如果是登录三次未成功,返回3,如果在三次之内成功,则返回登录的用户名
    """
    count = 0
    while count < 3:
        with open("userinfo_blogs.txt", "r", encoding="UTF-8") as f3:
            flage = False
            login_user = input("请输入登录用户名:").replace(" ", "")
            login_pwd = input("请输入登录密码:").replace(" ", "")
            for i in f3:
                if login_user.strip() == i.strip().split(":")[0] and login_pwd.strip() == i.strip().split(":")[1]:
                    # print(a,b)
                    flage = True
                    break
                # print(login_user,login_pwd)
                # print(i.split(":")[0],i.split(":")[1])
            if flage == False:
                # print(login_user)
                # print(login_pwd)
                print("登录失败!")
                count += 1
            else:
                print("登陆成功!")
                global flag
                flag = True
                return login_user
    return count

def register():
    """
    注册功能
    :return:注册用户名和密码
    """
    while 1:
        error_flag = True
        user = input("请输入注册用户名:")
        for i in user:
            if not (48 <= ord(i) <= 57 or 65 <= ord(i) <= 90 or 97 <= ord(i) <= 122):
                print("请输入正确的用户名!")
                error_flag = False
                break
        if error_flag:
            pwd = input("请输入注册密码:")
            if not(6 <= len(pwd) <= 14):
                print("密码要在6~14个字符之间")
            else:
                break
    return user,pwd
def article(ret_login):
    """
    文章页面
    :param ret_login: 登陆的用户名
    :return:
    """
    print(f"欢迎{ret_login}进入文章页面!")
def comment(ret_login):
    """
    评论页面
    :param ret_login: 登陆的用户名
    :return:
    """
    print(f"欢迎{ret_login}进入评论页面!")
def diary(ret_login):
    """
    日记页面
    :param ret_login: 登陆的用户名
    :return:
    """
    print(f"欢迎{ret_login}进入日记页面!")
def collection(ret_login):
    """
    收藏页面
    :param ret_login: 登陆的用户名
    :return:
    """
    print(f"欢迎{ret_login}进入收藏页面!")
def log_off():
    """
    注销登录功能,从登录状态变成未登录状态
    :return:
    """
    print("注销成功!")
    global flag
    flag = False
def exit():
    print("退出成功!")
    return "break"
while 1:
    num = input("请输入序号:")
    if num.isdecimal() and 1 <= int(num) <= 7:
        num = int(num)
        if num == 1:
            reg_user,reg_pwd = register()
            # print(a,b)
            with open("userinfo_blogs.txt", "r", encoding="UTF-8") as f:
                reg_flag = True
                for i in f:
                    i = i.split(":")
                    if reg_user == i[0]:
                        print("用户名已存在!")
                        reg_flag = False
                if reg_flag == True:
                    with open("userinfo_blogs.txt", "a", encoding="UTF-8") as f1:
                        f1.write(f"{reg_user}:{reg_pwd}\n")
                        print("注册成功!")
        elif num == 2:
            ret_login = login()
            if str(ret_login) == "3":
                print("您已经超过三次登录还未成功!")
                print("已退出程序!")
                break

        elif num == 3:
            if not flag:
                print("请先登录!")
                ret_login = login()
                if str(ret_login) == "3":
                    print("您已经超过三次登录还未成功!")
                    print("已退出程序!")
                    break
                article(ret_login)
            else:
                article(ret_login)
        elif num == 4:
            if not flag:
                print("请先登录!")
                ret_login = login()
                if str(ret_login) == "3":
                    print("您已经超过三次登录还未成功!")
                    print("已退出程序!")
                    break
                comment(ret_login)
            else:
                comment(ret_login)
        elif num == 5:
            if not flag:
                print("请先登录!")
                ret_login = login()
                if str(ret_login) == "3":
                    print("您已经超过三次登录还未成功!")
                    print("已退出程序!")
                    break
                diary(ret_login)
            else:
                diary(ret_login)
        elif num == 6:
            if not flag:
                print("请先登录!")
                ret_login = login()
                if str(ret_login) == "3":
                    print("您已经超过三次登录还未成功!")
                    print("已退出程序!")
                    break
                collection(ret_login)
            else:
                collection(ret_login)
        elif num == 7:
            if not flag:
                print("请先登录!")
                ret_login = login()
                if str(ret_login) == "3":
                    print("您已经超过三次登录还未成功!")
                    print("已退出程序!")
                    break
                log_off()
            else:
                log_off()
    elif num == '8':
        br_k = exit()
        try:
            eval(br_k)
        except SyntaxError:
            break
    else:
        print("请输入正确的序号!")

Guess you like

Origin www.cnblogs.com/zhangchaoyin/p/11221188.html