tishi = """
*****************************************************
【学生成绩管理系统】
q. 退出学生成绩系统
1. 显示学生成绩信息
2. 新建学生成绩信息
3. 查询学生成绩信息
4. 删除学生成绩信息
5. 修改学生名字信息
6. 查询及格学生信息
******************************************************"""
students_list = []
students_60 = []
class Student:
def __init__(self,num:int,name:str,sex:str,grade:float):
self.num = num
self.name = name
self.sex = sex
self.grade = grade
def modify_by_name(self,new_name):
self.name = new_name
def display(students_list):
print("1. 显示全部信息")
print("学号\t姓名\t性别\t成绩\t")
for stu in students_list:
print(f'{stu.num}\t{stu.name}\t{stu.sex}\t{stu.grade}')
def add():
global students_list
num = int(input("请输入学生的学号:"))
name = input("请输入学生的名字:")
sex = input("请输入学生性别:")
grade = int(input("请输入学生分数:"))
student = Student(num=num,name=name,sex=sex,grade=grade)
students_list.append(student)
def delect():
global students_list
cnum = int(input("请输入需要删除的学生学号:"))
for each in students_list:
if each.num == cnum:
students_list.remove(each)
else:
print("查无此人,请重新输入")
def find_by_num():
global students_list
cnum = int(input("请输入需要查询成绩的学生学号:"))
for each in students_list:
if each.num == cnum:
print(f"此学生的成绩为{each.grade}")
return "查无此人,请重新输入"
def modify_by_name():
global students_list
name = input("请输入需要修改的学生名字:")
for each in students_list:
if each.name == name:
each.modify_by_name(input("请输入正确的学生名字"))
return '改名成功'
return f'找不到学生{name}'
def select_by_num_60():
global students_list
global students_60
for each in students_list:
if each.grade >= 60:
students_60.append(each.name)
print(students_60)
while True:
print(tishi)
handle = input('请选择你要的操作选项:')
if handle == 'q':
print('q. 退出系统')
break
elif handle == '1':
display(students_list)
elif handle == '2':
add()
elif handle == '3':
print(find_by_num())
elif handle == '4':
delect()
elif handle == '5':
print(modify_by_name())
elif handle == '6':
select_by_num_60()
else:
print('请输入正确的操作选项!')
|