1.声明一个字典保存一个学生的信息,学生信息中包括: 姓名、年龄、成绩(单科)、电话
print("======================第1题============================")
student_dict = {"姓名":"光头强","年龄":18,"成绩(单科)":100,"电话":"12345678912"}
print(student_dict)
2.声明一个列表,在列表中保存6个学生的信息(6个题1中的字典)
student_list=[
{"姓名":"光头强","年龄":18,"成绩(单科)":100,"电话":"13045678912"},
{"姓名":"熊大","年龄":17,"成绩(单科)":45,"电话":"1311321323"},
{"姓名":"熊二","年龄":16,"成绩(单科)":98,"电话":"13221321338"},
{"姓名":"熊三","年龄":20,"成绩(单科)":59,"电话":"13345678912"},
{"姓名":"熊四","年龄":14,"成绩(单科)":96,"电话":"13445678912"},
{"姓名":"熊五","年龄":13,"成绩(单科)":95,"电话":"13545678918"}
]
a.统计不及格学生的个数
print("=============问题a============")
count1 = 0
for student_dict in student_list:
if student_dict["成绩(单科)"] < 60:
count1 += 1
print(count1)
b.打印不及格学生的名字和对应的成绩
print("=============问题b============")
for student_dict in student_list:
if student_dict["成绩(单科)"] < 60:
print(student_dict["姓名"],student_dict["成绩(单科)"])
c.统计未成年学生的个数
print("=============问题c============")
count2 = 0
for student_dict in student_list:
if student_dict["年龄"] < 18:
count2 += 1
print(count2)