1.声明一个字典保存一个学生的信息,学生信息中包括: 姓名、年龄、成绩(单科)、电话
student1 = {'name': '小华', 'age': 18, 'grade': '79','tel': '13222223435'}
2.声明一个列表,在列表中保存6个学生的信息(6个题1中的字典)
a.统计不及格学生的个数
b.打印不及格学生的名字和对应的成绩
c.统计未成年学生的个数
d.打印手机尾号是8的学生的名字
e.打印最高分和对应的学生的名字
student = [
{'name': '喜洋洋', 'age': 16, 'grade': 100,'tel': 13222223438},
{'name': '美洋洋', 'age': 15, 'grade': 95, 'tel': 13222223435},
{'name': '沸羊羊', 'age': 17, 'grade': 86, 'tel': 13222223435},
{'name': '懒洋洋', 'age': 14, 'grade': 43, 'tel': 13222223435},
{'name': '红太狼', 'age': 24, 'grade': 53, 'tel': 13222223435},
{'name': '灰太狼', 'age': 25, 'grade': 79, 'tel': 13222223435}
]
list1 = []
count = 0
count1 = 0
g_max = 0
youxiurencai = ''
for people in student:
for grade in people:
if people['grade'] < 60:
print('不及格学生姓名:', people['name'],'成绩', people['grade'])
count += 1
break
for age in people:
if people['age'] < 18:
count1 += 1
break
for tel in people:
if people['tel'] % 10 == 8:
print('手机尾号是8的学生:',people['name'])
break
for grade in people:
if people['grade'] > g_max:
g_max = people['grade']
for name in people:
if people['grade'] == g_max:
youxiurencai = people['name']
print('不及格学生个数:', count, '未成年人数:', count1)
print('最高分:', g_max,'优秀人才:', youxiurencai)
f.将列表按学生成绩从大到小排序(挣扎一下,不行就放弃)
students = [
{'name': '喜洋洋', 'age': 16, 'grade': 85, 'tel': 13222223438},
{'name': '美洋洋', 'age': 15, 'grade': 95, 'tel': 13222223435},
{'name': '沸羊羊', 'age': 17, 'grade': 86, 'tel': 13222223435},
{'name': '懒洋洋', 'age': 14, 'grade': 43, 'tel': 13222223435},
{'name': '红太狼', 'age': 24, 'grade': 53, 'tel': 13222223435},
{'name': '灰太狼', 'age': 25, 'grade': 79, 'tel': 13222223435}
]
new_list = []
while True:
garde1 = 0
for student in students:
if student['grade'] > garde1:
garde1 = student['grade']
dictx = student
new_list.append(dictx)
students.remove(dictx)
if students == []:
break
print(new_list)