以下代码,所有变量用拼音命名:
# 定义一个学生列表
xue_sheng_lie_biao
=
[]
# 循环输入学生信息,直到输入的学生姓名为 "结束" 为止
while
True
:
# 输入学生姓名
xing_ming
=
input
(
"请输入学生姓名(输入「结束」退出):"
)
if
xing_ming
==
"结束"
:
break
# 输入学生成绩
yu_wen_cheng_ji
=
float
(
input
(
"请输入语文成绩:"
))
shu_xue_cheng_ji
=
float
(
input
(
"请输入数学成绩:"
))
ying_yu_cheng_ji
=
float
(
input
(
"请输入英语成绩:"
))
# 计算学生总成绩和平均成绩
zong_cheng_ji
=
yu_wen_cheng_ji
+
shu_xue_cheng_ji
+
ying_yu_cheng_ji
ping_jun_cheng_ji
=
zong_cheng_ji
/
3
# 将学生信息添加到列表中
xue_sheng_lie_biao
.
append
({
"姓名"
:
xing_ming
,
"语文成绩"
:
yu_wen_cheng_ji
,
"数学成绩"
:
shu_xue_cheng_ji
,
"英语成绩"
:
ying_yu_cheng_ji
,
"总成绩"
:
zong_cheng_ji
,
"平均成绩"
:
ping_jun_cheng_ji
})
# 计算全班总成绩和平均成绩
quan_ban_zong_cheng_ji
=
sum
([
x
[
"总成绩"
]
for
x
in
xue_sheng_lie_biao
])
quan_ban_ping_jun_cheng_ji
=
quan_ban_zong_cheng_ji
/
len
(
xue_sheng_lie_biao
)
# 输出每个学生的成绩信息
for
xue_sheng
in
xue_sheng_lie_biao
:
print
(
"姓名:"
,
xue_sheng
[
"姓名"
])
print
(
"语文成绩:"
,
xue_sheng
[
"语文成绩"
])
print
(
"数学成绩:"
,
xue_sheng
[
"数学成绩"
])
print
(
"英语成绩:"
,
xue_sheng
[
"英语成绩"
])
print
(
"总成绩:"
,
xue_sheng
[
"总成绩"
])
print
(
"平均成绩:"
,
xue_sheng
[
"平均成绩"
])
print
(
"------------------------"
)
# 输出全班成绩统计信息
print
(
"全班总成绩:"
,
quan_ban_zong_cheng_ji
)
print
(
"全班平均成绩:"
,
quan_ban_ping_jun_cheng_ji
)
接下来,改成用英语命名:
# 定义一个学生列表
students_list
=
[]
# 循环输入学生信息,直到输入的姓名为 "end"
while
True
:
# 输入学生姓名
name
=
input
(
"输入学生姓名(输入 'end' 结束):"
)
if
name
==
"end"
:
break
# 输入学生各科成绩
chinese_grade
=
float
(
input
(
"输入语文成绩:"
))
math_grade
=
float
(
input
(
"输入数学成绩:"
))
english_grade
=
float
(
input
(
"输入英语成绩:"
))
# 计算总分和平均分
total_grade
=
chinese_grade
+
math_grade
+
english_grade
avg_grade
=
total_grade
/
3
# 将学生信息添加到列表中
students_list
.
append
({
"姓名"
:
name
,
"语文成绩"
:
chinese_grade
,
"数学成绩"
:
math_grade
,
"英语成绩"
:
english_grade
,
"总分"
:
total_grade
,
"平均分"
:
avg_grade
})
# 计算整个班级的总分和平均分
class_total_grade
=
sum
([
x
[
"总分"
]
for
x
in
students_list
])
class_avg_grade
=
class_total_grade
/
len
(
students_list
)
# 输出每个学生的成绩信息
for
student
in
students_list
:
print
(
"姓名:"
,
student
[
"姓名"
])
print
(
"语文成绩:"
,
student
[
"语文成绩"
])
print
(
"数学成绩:"
,
student
[
"数学成绩"
])
print
(
"英语成绩:"
,
student
[
"英语成绩"
])
print
(
"总分:"
,
student
[
"总分"
])
print
(
"平均分:"
,
student
[
"平均分"
])
print
(
"------------------------"
)
# 输出班级成绩统计信息
print
(
"班级总分:"
,
class_total_grade
)
print
(
"班级平均分:"
,
class_avg_grade
)
对比看,你的感受如何?评论区告诉我 - -