PYTHON面向对象之学生管理系统!

Chipo ·
更新时间:2024-09-20
· 847 次阅读

python面向对象之学生管理系统

话不多说,先看看代码(求关注+赞,努力写出好的东西!…_ 谢谢!!)

#哪里有所不妥可以修改
#python面向对象之学生管理系统
import sys

class StudentManage:
student_list = []

#添加学生信息 def rank_score(self): b = int(input('降序还是逆序?')) self.student_list.sort(key = lambda x:int(x[5]),reverse = b) def rank_number(self): c = int(input('将序还是升序?')) self.student_list.sort(key = lambda x:int(x[1]),reverse = c) def print_students(self): title_old = ['学号','姓名','python','数学','英语','总分'] print('\t'.join(title_old)) for each_list in self.student_list: print('\t'.join(each_list)) def creat_new(self): with open('new.score.txt','w') as new_F: title_new = ['学号','姓名','python','数学','英语','总分'] new_F.write('\t'.join(title_new)+'\n') for each_new in self.student_list: new_F.write('\t'.join(each_new)+'\n') print('创建新的成绩单成功!!!') def add_student(self): new_student = [] self.number = input('请输入姓名:') self.name = input('请输入学号:') self.python = input('请输入python的分数:') self.math = input('请输入数学的分数:') self.English =input('请输入英语的分数:') new_student.append(self.number) new_student.append(self.name) new_student.append(self.python) new_student.append(self.math) new_student.append(self.English) new_student.append(str(int(self.python)+int(self.math)+int(self.English))) self.student_list.append(new_student) def read_in(self): with open('score.txt') as F: #一般文件的第一行为标题行,我们先不考虑 F.readline() #移动文件指针到第一行末尾 for each_line in F: read_new = [] read_new = each_line.strip('\n').split('\t') #之间的间隔都是tab read_new.append(str(int(read_new[2])+int(read_new[3])+int(read_new[4]))) self.student_list.append(read_new) def menu(self): while True: s1 = '某某大学学生管理系统' s2 = '1.读入已有学生信息' s3 = '2.添加学生信息' s4 = '3.以总成绩排序(1降序,0升序)' s5 = '4.以学号排序(1降序,0升序)' #总分 s8 = '5.打印当前学生信息' s6 = '6.存入一个新的文件中' s7 = '7.退出' print(s1.center(20,'-'),s2.ljust(20),s3.ljust(20),s4.ljust(20),s5.ljust(20),s6.ljust(20),s8.ljust(20),s7.ljust(20),sep = '\n') choice = int(input('CHOICE:')) if choice == 1: self.read_in() self.print_students() if choice == 2: self.add_student() self.print_students() if choice == 3: self.rank_score() self.print_students() if choice == 6: self.creat_new() if choice == 5: self.print_students() if choice == 7: sys.exit(0) if choice == 4: self.rank_number() self.print_students()

aa = StudentManage()
print(aa.menu())
原创文章 1获赞 6访问量 178 关注 私信 展开阅读全文
作者:冷冷amazing



python面向对象 学生管理系统 对象 系统 Python

需要 登录 后方可回复, 如果你还没有账号请 注册新账号