python实验练习-图书管理系统(使用文件来实现)

题目

功能描述:
图书管理系统项目功能描述:
(1)创建txt文本文档,包含如下:
① books.txt:保存有一些书籍名称;
② users.txt:用于保存用户相关的信息;
③ users_book.txt:记录哪些用户借了哪些书
(2)程序包含用户注册、用户登录、查看图书、借阅图书等相关图书管理系统的功能。
(3)可根据自己对图书管理系统的理解增加其它功能。

将问题分析划分为如下内容完成:
(1)分别编写用户注册(register)模块、用户登录(login)模块、查看图书(show_books)模块、借阅图书(borrow_book)模块,并将成功注册的用户名和密码保存在文件users.txt中,已有书籍名称保存在books.txt中,哪些用户借阅了哪些图书保存在users_book.txt中;
(2)主函数中可实现根据提示依次调用用户注册、用户登录、查看图书、借阅图书等功能。

代码

# author:dq
# project:PythonProject
# date:2021年11月04日
# function:

# ① books.txt:保存有一些书籍名称;
# ② users.txt:用于保存用户相关的信息;
# ③ users_book.txt:记录哪些用户借了哪些书

import os
# 创建txt文件
def create(path):
    file = open(path, 'a')
    file.close()

booksPath = "./book.txt"
usersPath = "./users.txt"
usersBookPath = "./users_book.txt"

# create(booksPath)
# create(usersPath)
# create(usersBookPath)

# 计算已有多少数量
def count(path):
    read = open(path, 'r', encoding='utf-8')
    count = len(read.readlines())
    read.close()
    return count

# 用户注册(register)模块、
def register(name, password):
    id = count(usersPath)
    users = open(usersPath, 'r', encoding='utf-8')
    isExist = False
    while True:
        info = users.readline()
        if info:
            if (name in info):
                isExist = True
                break
        else:
            break
    users.close()
    if isExist == True:
        print

你可能感兴趣的:(python基础知识,python,图书馆管理系统,文件读写)