Python学生信息管理

Python实现学生信息管理

  • 共包括四个模块,每个模块负责不同的工作
  • ui.py中包含菜单和功能信息的联系
  • bll.py中实现学生信息的增删查改,文件读取导出,学生分数排序等操作
  • main.py调用菜单,model.py定义学生的基本信息构成

model.py

class StudentModel:
    def __init__(self, id, name, age, score, item):
        self.id = id
        self.name = name
        self.age = age
        self.score = score
        self.item = item

sm = StudentModel('1', '张三', '19', '90', '1')

bll.py

from StudentMangementSystem.model import sm


class StudentMangerController:
    # 创建一个空列表,存储学员信息
    new_List = []
    newList = []
    # 显示文件中学生信息
    def show_student_infile(self):
        f = open('E:\\Python\\Test\\StudentMangementSystem\\student_information.txt', 'r')
        content = f.read()
        print('当前文件中内容为:')
        print('----------------------')
        print(content)

    # 读取已添加的学生信息到列表
    def output_student_inlist(self):
        self.newList.clear()
        newDict = {
   '学号': '20194051120', '姓名': 'yst', '年龄': '19', '分数': '90', '----------------------': ''}
        with open('E:\\Python\\Test\\StudentMangementSystem\\student_information.txt', 'r') as f:
            i = 0
            for line in f:
                splitLine = line.split()
                newDict[str(splitLine[0])] = ",".join(splitLine[1:])
                i = i + 1
                if i % 5 == 0:
                    del newDict['----------------------']
                    self.newList.append(newDict)
                    # 因为newDict 地址不变,如果不创建一个新的newDict 的值将会重复输入 ,所以重新创建一个字典
                    newDict = {
   }
        for i in self.newList:
            i['学号'] = int(i['学号'])
            i['年龄'] = int(i['年龄'])
            i['分数'] = int(i['分数'])
        print('成功读取到列表,内容如下')
        for i in self.newList:
            print(i)
        smc.new_List = self.newList

    # 测试学生学号录入
    def test_input_id(self):
        try:
            sm.id = int(input('请输入学号:'))
        except  ValueError:
            print('输入错误,请输入正确的学号')
            smc.test_input_id()
        return sm.id

    # 测试学生年龄录入
    def test_input_age(self):
        try:
            sm.age = int(input('请输入年龄:'))
            if sm.age < 10 or sm.age > 30:
                print('请输入正确的年龄:')
                smc.test_input_age()
        except  ValueError:
            print('输入错误,请输入正确的年龄')
            smc.test_input_age()
        return sm.age

    # 测试学生分数录入
    def test_input_score(self):
        try:
            sm.score = int(input('请输入分数:'))
            if sm.score < 0 or sm.score > 100:
                print('请输入正确的分数:')
                smc.test_input_score()
        except  ValueError:
            print('输入错误,请输入正确的分数')
            smc.test_input_score()
        return sm.score

    # 添加学生信息
    def add_student(self):
        # 提示用户输入信息
        smc.test_input_id()
        # 判断是否添加这个学生信息,如果学生存在就报错,否则添加数据
        global new_List
        for i in smc.new_List:
            if sm.id == i['学号&
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值