栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python八九天作业

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python八九天作业

控制台版文章管理系统:
    1、用户管理系统
    2、文章的管理和控制
    3、宠物管理【扩展功能】

import json
import sys
import os
import time
import hashlib


def write(article_new):
    while True:
        with open(article_new, "a") as fle:
            w = fle.write(input('请输入:') + 'n')
            fle.flush()
        if w == 0:
            break


def read(article_new):
    with open(article_new, "r") as fle:
        w = fle.readlines()
        for word in w:
            print(word)


def login(login_ls):
    name = input('请输入用户名:')
    if name in login_ls:
        password = int(input('请输入密码:'))
        if password == int(login_ls[name]):
            print('登录成功!')
            return True
        else:
            print('密码错误!')
            return False
    else:
        print('该用户不存在!')
        return False


def enroll():
    enroll_ls = dict()
    name = input('请输入注册的用户名:')
    password = int(input('请输入密码:'))
    if input('是否注册') == 'yes' or input('是否注册') == 'Yes':
        change = input('是否加密')
        if change == 'yes' or change == 'Yes':
            password = md5(password)
        enroll_ls[name] = password
        print('注册成功!')
        return enroll_ls
    else:
        print('注册失败!')
        return enroll_ls


def md5(password):
    password = str(password)
    password1 = hashlib.md5()
    password1.update(password.encode("utf8"))
    password = password1.hexdigest()
    return password


def get_ls():
    article = os.listdir("D:\python\IO\ls")
    print('文章目录')

    for i in range(0, len(article)):
        print(f'{i + 1}.{article[i]}')

    option = int(input('输入要查找的文件的数字:'))
    article_new = os.path.join("D:\python\IO\ls", article[option - 1])
    now_time = time.strftime("%Y-%m-%d %H:%M:%S")
    old_time = time.ctime(os.path.getctime(article_new))
    change_time = time.ctime(os.path.getmtime(article_new))
    article_dig = os.path.getsize(article_new)
    print(f'文件:{article[option]}n文件大小{article_dig}n当前时间{now_time}')
    print(f'文件创建时间{old_time}n文件修改时间{change_time}')
    read(article_new)
    option1 = input('是否继续')

    if option1 == 'yes' or 'Yes':
        write(article_new)


if __name__ == "__main__":
    print(' ' * 10 + '登录界面')
    print('~ * ' * 10)
    print(' ' * 12 + '1. 用户登录n' + ' ' * 12 + '2. 新用户注册n' + ' ' * 12 + '3. 退出系统')
    print('~ * ' * 10)
    option1 = int(input('(温馨提示)请输入您的选项:'))
    if option1 == 1:
        ls = open("D:\python\python3\a.txt", 'r')
        login_ls = json.load(ls)
        print(login_ls)
        ls.close()

        if login(login_ls):
            get_ls()


    elif option1 == 2:
        enroll_dict = enroll()
        json.dump(enroll_dict, open("D:\python\IO\ls.txt", 'w'))

    elif option1 == 3:

        sys.exit()

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/869761.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号