"""禿子養(yǎng)成記"""
1聲明一個字典保存一個學(xué)生的信息,學(xué)生信息中包括: 姓名、年齡、成績(單科)、電話
student={'name':'嚴(yán)
朗','age':23,'score':100,'tel':'18324929334'}
2.聲明一個列表,在列表中保存6個學(xué)生的信息(6個題1中的字典)
students=[{'name':'嚴(yán)朗','age':23,'score':100,'tel':'18324929334'},
{'name':'小明','age':21,'score':89,'tel':'18978923929'},
{'name':'小花','age':22,'score':57,'tel':'15324923737'},
{'name':'小強(qiáng)','age':17,'score':60,'tel':'183249294334'},
{'name':'小狗','age':26,'score':78,'tel':'15824924338'},
{'name':'小黑','age':18,'score':56,'tel':'13324929738'}
]
a.統(tǒng)計不及格學(xué)生的個數(shù)
a=0
for x in students:
if x['score']<60:
a+=1
print('不及格的學(xué)生有%d個'% (a))
b.打印不及格學(xué)生的名字和對應(yīng)的成績
for x in students:
if x['score']<60:
print(x['name'],x['score'])
c.統(tǒng)計未成年學(xué)生的個數(shù)
a=0
for x in students:
if x['age']<18:
a+=1
print('未成年的學(xué)生有%d個'%(a))
d.打印手機(jī)尾號是8的學(xué)生的名字
for x in students:
if x['tel'][-1]=='8':
print(x['name'])
e.打印最高分和對應(yīng)的學(xué)生的名字
list1=[]
for x in students:
list1.append(x['score'])
a=max(list1)
if a==x['score']:
print(a,x['name'])
f.將列表按學(xué)生成績從大到小排序(掙扎一下,不行就放棄)
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)