2019-03-13

"""禿子養(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)

3.

嘗試實現(xiàn)學(xué)生管理系統(tǒng)的界面(見視頻)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容