#!/usr/bin/python3
info = """
*********************************
欢迎使用【学生信息管理系统】v1.0
1.新建学生信息
2.显示全部信息
3.查询学生信息
4.删除学生信息
5.修改学生信息
0.退出系统
*********************************
"""
import json
print(info)
'''
students = [
{'name':'张三', 'math':65, 'chinese':65, 'english':65, 'total':195},
{'name':'李四', 'math':65, 'chinese':65, 'english':65, 'total':195},
{'name':'王五', 'math':65, 'chinese':65, 'english':65, 'total':195}
]
'''
with open('students.json',mode = 'r',encoding = 'utf-8') as f:
text = f.read()
students = json.loads(text)
while True:
#从外部输入用户的操作
action = input('请选择你想要进行的操作:')
#增删改查,应该在哪里面操作
if action =='1':
print('1.新建学生信息')
name = input('请输入学生的姓名:')
math = int(input('请输入学生的数学成绩:'))
chinese = int(input('请输入学生的语文成绩:'))
english = int(input('请输入学生的英语成绩:'))
total = math + chinese + english
students.append({'name':name, 'math':math, 'chinese':chinese, 'english':english, 'total':total})
elif action =='2':
print('2.显示全部信息')
print('姓名\t数学\t语文\t英语\t总分')
for student in students:
print('{}\t{}\t{}\t{}\t{}'.format(*student.values()))
elif action =='3':
#print('3.查询学生信息')
name = input('请输入你想查询的学生姓名:')
for student in students:
if student['name'] ==name:
print('姓名\t数学\t语文\t英语\t总分')
print('{}\t{}\t{}\t{}\t{}'.format(*student.values()))
break
else:
print(f'{name} 这个学员不存在')
elif action =='4':
#print('4.删除学生信息')
name = input('请输入你想删除的学生姓名:')
for student in students:
if student['name'] ==name:
#del pop remove 三种方式删除列表
#students.remove(student)
#del students[students.index(student)]
students.pop(students.index(student))
break
else:
print(f'{name} 这个学员不存在')
elif action =='5':
#print('5.修改学生信息')
name = input('请输入你想修改的学生姓名:')
print('(如果输入为空,就不修改学生信息)')
for student in students:
if student['name'] ==name:
#如果不输内容,就不进行修改成绩
math = input('请重新输入学生的数学成绩:')
if math:
math = int(math)
student['math'] = math
chinese = input('请重新输入学生的语文成绩:')
if chinese:
chinese = int(chinese)
student['chinese'] = chinese
english = input('请重新输入学生的英语成绩:')
if english:
english = int(english)
student['english'] = english
student['total'] = student['math'] + student['chinese'] + student['english']
break
else:
print(f'{name} 这个学员不存在')
elif action =='0':
print('0.退出系统')
with open('students.json',mode = 'w',encoding = 'utf-8') as f:
f.write(json.dumps(students, ensure_ascii=False))
break
else:
print('你输入的选项错了,请重新输入选项')
没有合适的资源?快使用搜索试试~ 我知道了~
python实战项目-学生成绩管理系统(基础版)
共2个文件
py:1个
json:1个
需积分: 0 0 下载量 167 浏览量
2024-04-30
16:25:00
上传
评论
收藏 2KB ZIP 举报
温馨提示
python实战项目-学生成绩管理系统(基础版)
资源推荐
资源详情
资源评论
收起资源包目录
students_basic.zip (2个子文件)
students_basic
students.json 304B
studentInfo.py 3KB
共 2 条
- 1
资源评论
竹雨.潇湘
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功