Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
文尔尔
学生成绩管理系统
提交
894defeb
学
学生成绩管理系统
项目概览
文尔尔
/
学生成绩管理系统
与 Fork 源项目一致
Fork自
inscode / Streamlit
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
学
学生成绩管理系统
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
894defeb
编写于
4月 18, 2024
作者:
2
2301_79952162
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Thu Apr 18 21:15:00 CST 2024 inscode
上级
0520122c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
241 addition
and
16 deletion
+241
-16
main.py
main.py
+241
-16
未找到文件。
main.py
浏览文件 @
894defeb
import
streamlit
as
st
from
streamlit_option_menu
import
option_menu
import
inscode
import
csv
# 设置Streamlit应用程序的标题
st
.
set_page_config
(
page_title
=
"app name"
,
layout
=
"wide"
)
# 读取学生信息csv文件并返回
def
read_students
():
with
open
(
'students.csv'
,
mode
=
'r'
)
as
file
:
reader
=
csv
.
DictReader
(
file
)
students
=
[
row
for
row
in
reader
]
return
students
menu1
=
"菜单1"
menu2
=
"菜单2"
# 将学生信息写入csv文件
def
write_students
(
students
):
fieldnames
=
[
'id'
,
'name'
,
'age'
,
'gender'
,
'grade'
]
with
open
(
'students.csv'
,
mode
=
'w'
,
newline
=
''
)
as
file
:
writer
=
csv
.
DictWriter
(
file
,
fieldnames
=
fieldnames
)
writer
.
writeheader
()
for
student
in
students
:
writer
.
writerow
(
student
)
with
st
.
sidebar
:
menu
=
option_menu
(
"菜单"
,
[
menu1
,
menu2
],
icons
=
[
'house'
,
"list-task"
],
menu_icon
=
"cast"
,
default_index
=
0
)
# 读取学生成绩csv文件并返回
def
read_scores
():
with
open
(
'scores.csv'
,
mode
=
'r'
)
as
file
:
reader
=
csv
.
DictReader
(
file
)
scores
=
[
row
for
row
in
reader
]
return
scores
def
main
():
# 将学生成绩写入csv文件
def
write_scores
(
scores
):
fieldnames
=
[
'id'
,
'subject'
,
'score'
]
with
open
(
'scores.csv'
,
mode
=
'w'
,
newline
=
''
)
as
file
:
writer
=
csv
.
DictWriter
(
file
,
fieldnames
=
fieldnames
)
writer
.
writeheader
()
for
score
in
scores
:
writer
.
writerow
(
score
)
# 添加学生信息
def
add_student
(
students
):
st
.
write
(
'添加学生信息'
)
id
=
st
.
text_input
(
'学号'
)
name
=
st
.
text_input
(
'姓名'
)
age
=
st
.
text_input
(
'年龄'
)
gender
=
st
.
selectbox
(
'性别'
,
[
'男'
,
'女'
])
grade
=
st
.
text_input
(
'年级'
)
if
st
.
button
(
'添加'
):
if
id
and
name
and
age
and
gender
and
grade
:
students
.
append
({
'id'
:
id
,
'name'
:
name
,
'age'
:
age
,
'gender'
:
gender
,
'grade'
:
grade
})
write_students
(
students
)
st
.
success
(
'添加成功'
)
else
:
st
.
error
(
'请填写完整的学生信息'
)
# 删除学生信息
def
delete_student
(
students
):
st
.
write
(
'删除学生信息'
)
id
=
st
.
text_input
(
'学号'
)
if
st
.
button
(
'删除'
):
if
id
:
index
=
-
1
for
i
,
student
in
enumerate
(
students
):
if
student
[
'id'
]
==
id
:
index
=
i
break
if
index
!=
-
1
:
del
students
[
index
]
write_students
(
students
)
st
.
success
(
'删除成功'
)
else
:
st
.
error
(
'学生信息不存在'
)
else
:
st
.
error
(
'请填写学号'
)
# 修改学生信息
def
edit_student
(
students
):
st
.
write
(
'修改学生信息'
)
id
=
st
.
text_input
(
'学号'
)
if
id
:
index
=
-
1
for
i
,
student
in
enumerate
(
students
):
if
student
[
'id'
]
==
id
:
index
=
i
break
if
index
!=
-
1
:
name
=
st
.
text_input
(
'姓名'
,
value
=
students
[
index
][
'name'
])
age
=
st
.
text_input
(
'年龄'
,
value
=
students
[
index
][
'age'
])
gender
=
st
.
selectbox
(
'性别'
,
[
'男'
,
'女'
],
index
=
(
0
if
students
[
index
][
'gender'
]
==
'男'
else
1
))
grade
=
st
.
text_input
(
'年级'
,
value
=
students
[
index
][
'grade'
])
if
st
.
button
(
'修改'
):
students
[
index
][
'name'
]
=
name
students
[
index
][
'age'
]
=
age
students
[
index
][
'gender'
]
=
gender
students
[
index
][
'grade'
]
=
grade
write_students
(
students
)
st
.
success
(
'修改成功'
)
else
:
st
.
error
(
'学生信息不存在'
)
else
:
st
.
error
(
'请填写学号'
)
# 查询学生信息
def
query_student
(
students
):
st
.
write
(
'查询学生信息'
)
id
=
st
.
text_input
(
'学号'
)
if
id
:
index
=
-
1
for
i
,
student
in
enumerate
(
students
):
if
student
[
'id'
]
==
id
:
index
=
i
break
if
index
!=
-
1
:
st
.
success
(
'查询成功'
)
st
.
write
(
'学号:'
,
students
[
index
][
'id'
])
st
.
write
(
'姓名:'
,
students
[
index
][
'name'
])
st
.
write
(
'年龄:'
,
students
[
index
][
'age'
])
st
.
write
(
'性别:'
,
students
[
index
][
'gender'
])
st
.
write
(
'年级:'
,
students
[
index
][
'grade'
])
else
:
st
.
error
(
'学生信息不存在'
)
else
:
st
.
error
(
'请填写学号'
)
if
menu
==
menu1
:
st
.
subheader
(
f
"
{
menu1
}
"
)
# 添加学生成绩
def
add_score
(
scores
):
st
.
write
(
'添加学生成绩'
)
id
=
st
.
text_input
(
'学号'
)
subject
=
st
.
text_input
(
'科目'
)
score
=
st
.
text_input
(
'成绩'
)
if
st
.
button
(
'添加'
):
if
id
and
subject
and
score
:
scores
.
append
({
'id'
:
id
,
'subject'
:
subject
,
'score'
:
score
})
write_scores
(
scores
)
st
.
success
(
'添加成功'
)
else
:
st
.
error
(
'请填写完整的成绩信息'
)
if
menu
==
menu2
:
st
.
subheader
(
f
"
{
menu2
}
"
)
# 删除学生成绩
def
delete_score
(
scores
):
st
.
write
(
'删除学生成绩'
)
id
=
st
.
text_input
(
'学号'
)
subject
=
st
.
text_input
(
'科目'
)
if
st
.
button
(
'删除'
):
if
id
and
subject
:
index
=
-
1
for
i
,
score
in
enumerate
(
scores
):
if
score
[
'id'
]
==
id
and
score
[
'subject'
]
==
subject
:
index
=
i
break
if
index
!=
-
1
:
del
scores
[
index
]
write_scores
(
scores
)
st
.
success
(
'删除成功'
)
else
:
st
.
error
(
'学生成绩不存在'
)
else
:
st
.
error
(
'请填写学号和科目'
)
if
__name__
==
'__main__'
:
main
()
# 修改学生成绩
def
edit_score
(
scores
):
st
.
write
(
'修改学生成绩'
)
id
=
st
.
text_input
(
'学号'
)
subject
=
st
.
text_input
(
'科目'
)
if
id
and
subject
:
index
=
-
1
for
i
,
score
in
enumerate
(
scores
):
if
score
[
'id'
]
==
id
and
score
[
'subject'
]
==
subject
:
index
=
i
break
if
index
!=
-
1
:
new_score
=
st
.
text_input
(
'成绩'
,
value
=
scores
[
index
][
'score'
])
if
st
.
button
(
'修改'
):
scores
[
index
][
'score'
]
=
new_score
write_scores
(
scores
)
st
.
success
(
'修改成功'
)
else
:
st
.
error
(
'学生成绩不存在'
)
else
:
st
.
error
(
'请填写学号和科目'
)
# 查询学生成绩
def
query_score
(
scores
):
st
.
write
(
'查询学生成绩'
)
id
=
st
.
text_input
(
'学号'
)
if
id
:
total_score
=
0
count
=
0
st
.
write
(
'学号:'
,
id
)
for
score
in
scores
:
if
score
[
'id'
]
==
id
:
st
.
write
(
'科目:'
,
score
[
'subject'
])
st
.
write
(
'成绩:'
,
score
[
'score'
])
total_score
+=
float
(
score
[
'score'
])
count
+=
1
if
count
>
0
:
st
.
write
(
'平均成绩:'
,
round
(
total_score
/
count
,
2
))
else
:
st
.
error
(
'学生成绩不存在'
)
# 登录认证
def
login
():
st
.
write
(
'登录认证'
)
user_type
=
st
.
selectbox
(
'用户类型'
,
[
'学生'
,
'教师'
,
'管理员'
])
username
=
st
.
text_input
(
'用户名'
)
password
=
st
.
text_input
(
'密码'
,
type
=
'password'
)
if
st
.
button
(
'登录'
):
if
user_type
==
'学生'
:
with
open
(
'students.csv'
,
mode
=
'r'
)
as
file
:
reader
=
csv
.
DictReader
(
file
)
for
row
in
reader
:
if
row
[
'id'
]
==
username
and
row
[
'name'
]
==
password
:
st
.
success
(
'登录成功'
)
return
True
elif
user_type
==
'教师'
:
if
username
==
'teacher'
and
password
==
'123456'
:
st
.
success
(
'登录成功'
)
return
True
elif
user_type
==
'管理员'
:
if
username
==
'admin'
and
password
==
'123456'
:
st
.
success
(
'登录成功'
)
return
True
st
.
error
(
'用户名或密码错误'
)
return
False
# 主函数入口
def
main
():
st
.
title
(
'学生成绩管理系统'
)
if
login
():
students
=
read_students
()
scores
=
read_scores
()
function
=
st
.
selectbox
(
'请选择功能'
,
[
'学生信息管理'
,
'成绩管理'
])
if
function
==
'学生信息管理'
:
operation
=
st
.
selectbox
(
'请选择操作'
,
[
'添加学生信息'
,
'删除学生信息'
,
'修改学生信息'
,
'查询学生信息'
])
if
operation
==
'添加学生信息'
:
add_student
(
students
)
elif
operation
==
'删除学生信息'
:
delete_student
(
students
)
elif
operation
==
'修改学生信息'
:
edit_student
(
students
)
elif
operation
==
'查询学生信息'
:
query_student
(
students
)
elif
function
==
'成绩管理'
:
operation
=
st
.
selectbox
(
'请选择操作'
,
[
'添加学生成绩'
,
'删除学生成绩'
,
'修改学生成绩'
,
'查询学生成绩'
])
if
operation
==
'添加学生成绩'
:
add_score
(
scores
)
elif
operation
==
'删除学生成绩'
:
delete_score
(
scores
)
elif
operation
==
'修改学生成绩'
:
edit_score
(
scores
)
elif
operation
==
'查询学生成绩'
:
query
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录