"""秃子养成记"""
1声明一个字典保存一个学生的信息,学生信息中包括: 姓名、年龄、成绩(单科)、电话
student={'name':'严
朗','age':23,'score':100,'tel':'18324929334'}
2.声明一个列表,在列表中保存6个学生的信息(6个题1中的字典)
students=[{'name':'严朗','age':23,'score':100,'tel':'18324929334'},
{'name':'小明','age':21,'score':89,'tel':'18978923929'},
{'name':'小花','age':22,'score':57,'tel':'15324923737'},
{'name':'小强','age':17,'score':60,'tel':'183249294334'},
{'name':'小狗','age':26,'score':78,'tel':'15824924338'},
{'name':'小黑','age':18,'score':56,'tel':'13324929738'}
]
a.统计不及格学生的个数
a=0
for x in students:
if x['score']<60:
a+=1
print('不及格的学生有%d个'% (a))
b.打印不及格学生的名字和对应的成绩
for x in students:
if x['score']<60:
print(x['name'],x['score'])
c.统计未成年学生的个数
a=0
for x in students:
if x['age']<18:
a+=1
print('未成年的学生有%d个'%(a))
d.打印手机尾号是8的学生的名字
for x in students:
if x['tel'][-1]=='8':
print(x['name'])
e.打印最高分和对应的学生的名字
list1=[]
for x in students:
list1.append(x['score'])
a=max(list1)
if a==x['score']:
print(a,x['name'])
f.将列表按学生成绩从大到小排序(挣扎一下,不行就放弃)
a=[]
students1=[]
for x in students:
a.append(x['score'])
a.sort(reverse= True)
for i in a:
for n in students:
if i==n['score']:
students1.append(n)
print(students1)