1.聲明一個(gè)字典保存一個(gè)學(xué)生的信息卜范,學(xué)生信息中包括: 姓名衔统、年齡、成績(jī)(單科)、電話
student = {'姓名': '葫蘆娃的爺爺', '年齡': '88', '成績(jī)': 88, '電話': 8008208820}
print(student)
3.用三個(gè)列表表示三門學(xué)科的選課學(xué)生姓名(一個(gè)學(xué)生可以同時(shí)選多門課)
a.求選課學(xué)生總共有多少人
math = ['lily', 'rose', 'rachel', 'rick']
chinese = ['rick', 'tom', 'jerry', 'mon']
history = ['mon', 'rick', 'lord', 'aaa']
math2 = set(math)
chinese2 = set(chinese)
history2 = set(history)
student =math2|chinese2|history2
# print(student)
print("總共學(xué)生個(gè)數(shù)是",len(student))
b.求只選了第一個(gè)學(xué)科的人的數(shù)量和對(duì)應(yīng)的名字
print('===================')
set2 = (math2 - chinese2) - history2
count = 0
for stu in set2:
count +=1
print("第一門學(xué)科的人數(shù):", len(set2))
print("名字:",set2)
c.求只選了一門學(xué)科的學(xué)生的數(shù)量和對(duì)應(yīng)的名字
only = math2^chinese2^history2 #-math2&chinese2&history2
print("只選了一個(gè)學(xué)科的人數(shù):", len(only))
print("名字是", only)
d.求只選了兩門學(xué)科的學(xué)生的數(shù)量和對(duì)應(yīng)的名字
c.求選了三門學(xué)生的學(xué)生的數(shù)量和對(duì)應(yīng)的名字
all = math2&chinese2&history2
print("都選了的人數(shù):", len(all))
print("名字是", all)
# 所有學(xué)生 - 只選了一科的學(xué)生 - 選了三科的學(xué)生
both = set2 - only - all
print("都選了的人數(shù):", len(both))
print("名字是", both)
2.聲明一個(gè)列表锦爵,在列表中保存6個(gè)學(xué)生的信息(6個(gè)題1中的字典)
student_six = [{'姓名': 'a', '年齡': '17', '成績(jī)': 88, 'tel': 8008208820},{'姓名': 'b', '年齡': '18', '成績(jī)': 90, 'tel': 8008208828},
{'姓名': 'c', '年齡': '18', '成績(jī)': 58, 'tel': 8008208820},{'姓名': 'd', '年齡': '19', '成績(jī)': 68, 'tel': 8008208826},
{'姓名': 'e', '年齡': '20', '成績(jī)': 23, 'tel': 8008208820},{'姓名': 'f', '年齡': '16', '成績(jī)': 81, 'tel': 8008208888}]
a.統(tǒng)計(jì)不及格學(xué)生的個(gè)數(shù)
b.打印不及格學(xué)生的名字和對(duì)應(yīng)的成績(jī)
count = 0
for i in range(len(student_six)):
if student_six[i].get('成績(jī)') < 60:
count+=1
print(student_six[i].get('姓名'),student_six[i].get('成績(jī)'))
print('不及格人數(shù):',count)
c.統(tǒng)計(jì)未成年學(xué)生的個(gè)數(shù)
count1 = 0
for i in range(len(student_six)):
if student_six[i].get('年齡') < '18':
count1 +=1
print("未成年人數(shù):",count1)
d.打印手機(jī)尾號(hào)是8的學(xué)生的名字
for i in range(len(student_six)):
if int(student_six[i].get('tel'))%10==8:
print(student_six[i].get('姓名'),student_six[i].get('tel'))
e.打印最高分和對(duì)應(yīng)的學(xué)生的名字
max_grade = 0
for i in range(len(student_six)):
if int(student_six[i].get('成績(jī)')) > max_grade:
max_grade = student_six[i].get('成績(jī)')
best_name = student_six[i].get('姓名')
print(max_grade,best_name)
f.將列表按學(xué)生成績(jī)從大到小排序(掙扎一下舱殿,不行就放棄)
print("=================fff====================")
for i in range(len(student_six)):
for j in range(len(student_six)):
if (int(student_six[i].get('成績(jī)'))) > (student_six[j].get('成績(jī)')): student_six[i],student_six[j]=student_six[j],student_six[i]
print(student_six)