day7-作業(yè)

##1.聲明一個(gè)字典保存一個(gè)學(xué)生的信息,學(xué)生信息中包括: 姓名、年齡、成績(jī)(單科)、電話、性別(男、女、不明)

dict1 = {'name': '瑞茲', 'age': 19, 'score': 90, 'phone': 
19988880000, 'gender': 'man'}

list1 = [{'name': '瑞茲', 'age': 25, 'score': 95, 'phone': 19988880000, 'gender': 'man'},
         {'name': '維恩', 'age': 16, 'score': 95, 'phone': 19988888888, 'gender': 'female'},
         {'name': '寒冰', 'age': 15, 'score': 70, 'phone': 19988881111, 'gender': 'female'},

         {'name': '龍女', 'age': 19, 'score': 80, 'phone': 19988882222, 'gender': 'female'},
         {'name': '德萊文', 'age': 18, 'score': 50, 'phone': 19988883333, 'gender': 'unknown'},
         {'name': '嘉文', 'age': 17, 'score': 59, 'phone': 19988885555, 'gender': 'man'}
         ]

1.統(tǒng)計(jì)不及格學(xué)生的個(gè)數(shù)

count = 0
for stu in list1:
    if stu['score'] < 60:
        count += 1
print(count)

2.打印不及格學(xué)生的名字和對(duì)應(yīng)的成績(jī)

for stu in list1:
    if stu['score'] < 60:
        print(stu['name'], stu['score'])

3.統(tǒng)計(jì)未成年學(xué)生的個(gè)數(shù)

for stu in list1:
    if stu['age'] < 18:
        count += 1
print('未成年學(xué)生個(gè)數(shù)為:', count)

4.打印手機(jī)尾號(hào)是8的學(xué)生的名字

for stu in list1:
    if stu['phone'] % 10 == 8:
        print('手機(jī)尾號(hào)是8的學(xué)生的名字是:', stu['name'])

5.打印最高分和對(duì)應(yīng)的學(xué)生的名字

max_score = 0
for stu in list1:
    if stu['score'] > max_score:
        max_score = stu['score']
for stu in list1:
    if max_score == stu['score']:
        print('最高分的學(xué)生為:', stu['name'])

7.刪除性別不明的所有學(xué)生

for stu in list1:
    if stu['gender'] != 'man' and stu['gender'] != 'female':
        list1.remove(stu)
print(list1)

3.用三個(gè)列表表示三門學(xué)科的選課學(xué)生姓名(一個(gè)學(xué)生可以同時(shí)選多門課)

chinese = ['寒冰', '嘉文', '瑞茲', '德萊文']
maths = ['希維爾', '瑞茲', '維恩', '寒冰']
english = ['希維爾', '德萊文', '瑞茲']

1.求選課學(xué)生總共有多少人

set1 = set(chinese)
set2 = set(maths)
set3 = set(english)
print('選課學(xué)生總共有%d人' % len(set1 | set2 | set3), '分別為:', set1 | set2 | set3)

2.求只選了第一個(gè)學(xué)科的人的數(shù)量和對(duì)應(yīng)的名字

print(len(set1 - set2 - set3), set1 - set2 - set3)

3.求只選了一門學(xué)科的學(xué)生的數(shù)量和對(duì)應(yīng)的名字

count = 0
x = ''
y = ''
z = ''
for stu in set1:
    if stu not in set2 and set3:
        x = x + ' ' + stu
        count += 1
for stu in set2:
    if stu not in set1 and set3:
        print(stu)
        y = y + ' ' + stu
        count += 1
for stu in set3:
    if stu not in set1 and set2:
        z = z + ' ' + stu
        count += 1
print('只選了一門學(xué)科的學(xué)生的數(shù)量為:', count, '名字是:', x, y, z)

4.求只選了兩門學(xué)科的學(xué)生的數(shù)量和對(duì)應(yīng)的名字

x = ''
y = ''
z = ''
count = 0
for stu in set1:
    if stu in set2 and stu not in set3 or stu in set3 and stu not in set2:
        x = x + ' ' + stu
        count += 1
for stu in set2:
    if stu in set1 and stu not in set3 or stu in set3 and stu not in set1:
        y = y + ' ' + stu
        count += 1
for stu in set3:
    if stu in set1 and stu not in set2 or stu in set2 and stu not in set1:
        z = z + ' ' + stu
        count += 1
print(x, y, z, count)

5.求選了三門學(xué)生的學(xué)生的數(shù)量和對(duì)應(yīng)的名字

x = list(set(chinese) & set(maths) & set(english))
print(x)
print('===========================================================')
count = 0
for stu in chinese:
    if stu in maths and stu in english:
        print(stu)
        for stu in maths:
            if stu in chinese and stu in english:
                print(stu)
                for stu in english:
                    if stu in chinese and stu in maths:
                         print(stu)
                count += 1
print(count)
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 1.聲明一個(gè)字典保存一個(gè)學(xué)生的信息,學(xué)生信息中包括: 姓名、年齡、成績(jī)(單科)、電話、性別(男、女、不明) 2.聲...
    Ed97001閱讀 388評(píng)論 0 0
  • 1.聲明一個(gè)字典保存一個(gè)學(xué)生的信息,學(xué)生信息中包括: 姓名、年齡、成績(jī)(單科)、電話、性別(男、女、不明) 2.聲...
    風(fēng)月辭寒閱讀 248評(píng)論 0 0
  • 1.聲明一個(gè)字典保存一個(gè)學(xué)生的信息,學(xué)生信息中包括: 姓名、年齡、成績(jī)(單科)、電話、性別(男、女、不明) 2.聲...
    ______n___閱讀 198評(píng)論 0 0
  • 今天把精保的工具都給打上標(biāo)簽,讓客戶更清晰的看懂。我方便我門自己干活。
    d005a7da9b80閱讀 133評(píng)論 0 0
  • Create a color from HSL, and alpha values from 0 to 1.創(chuàng)建一...
    劉板栗閱讀 1,130評(píng)論 0 0

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