day8-作业

1.声明一个字典保存一个学生的信息,学生信息中包括: 姓名、年龄、成绩(单科)、电话

student = {'name':'张三','age':18,'score':90,'Tel':'13330131313'}

2.声明一个列表,在列表中保存6个学生的信息(6个题1中的字典)

all_student = [
{'name':'张一','age':18,'score':90,'Tel':'13330131313'},
{'name':'张二','age':19,'score':80,'Tel':'13330131314'},
{'name':'张三','age':19,'score':40,'Tel':'13330131315'},
{'name':'张四','age':18,'score':50,'Tel':'13330131316'},
{'name':'张五','age':20,'score':77,'Tel':'13330131317'},
{'name':'张六','age':17,'score':68,'Tel':'13330131318'}
]

a.统计不及格学生的个数

num = 0
for scores in  all_student:
     if scores.get('score') < 60 :
         num +=1
print('不及格人数:',num)

b.打印不及格学生的名字和对应的成绩

for scores in  all_student:
     if scores.get('score') < 60 :
         print('不及格名字:',scores.get('name'),'成绩:',scores.get('score'))

c.统计未成年学生的个数

year = 0
for years in  all_student:
    if years.get('age') < 18:
        year +=1
print('未成年人数:',year)

d.打印手机尾号是8的学生的名字

for num in  all_student:
     numbers = num.get('Tel')
     if numbers[-1] == '8':
        print('手机尾号为8的学生:',num.get('name'))

e.打印最高分和对应的学生的名字

max_score = 0
for stu_dict in all_student:
    if stu_dict['score'] > max_score:
        max_score = stu_dict['score']
for stu_dict in all_student:
    if stu_dict['score'] == max_score:
        print(stu_dict['name'],max_score)

f.将列表按学生成绩从大到小排序(挣扎一下,不行就放弃)

all_student.sort(key=lambda x:x['score'],reverse = True)
print(all_student)
day8-作业_第1张图片
12.jpg

你可能感兴趣的:(day8-作业)