1.聲明一個字典保存一個學(xué)生的信息,學(xué)生信息中包括: 姓名蹦哼、年齡鳄哭、成績(單科)、電話
message1={'name':'張三',
'age':20,
'grade':70,
'telephone':'112'
}
2.聲明一個列表纲熏,在列表中保存6個學(xué)生的信息(6個題1中的字典)
message2={'name':'小明',
'age':22,
'grade':50,
'telephone':'123',
}
message3={'name':'小紅',
'age':27,
'grade':99,
'telephone':'562',
}
message4={'name':'小王',
'age':19,
'grade':59,
'telephone':'568',
}
message5={'name':'小李',
'age':17,
'grade':77,
'telephone':'114',
}
message6={'name':'小超',
'age':20,
'grade':25,
'telephone':'115',
}
t=[message1,message2,message3,message4,message5,message6]
a.統(tǒng)計不及格學(xué)生的個數(shù)
count =0
for item in t:
if item['grade']<60:
count +=1
print(count)
b.打印不及格學(xué)生的名字和對應(yīng)的成績
for item in t:
if item['grade']<60:
print(item['name'],item['grade'])
c.統(tǒng)計未成年學(xué)生的個數(shù)
count=0
for item in t:
if item['age']<18:
count+=1
print(count)
d.打印手機尾號是8的學(xué)生的名字
for item in t:
if item['telephone'][len(item['telephone'])-1]=='8':
print(item['name'])
e.打印最高分和對應(yīng)的學(xué)生的名字
i=0
for item in t:
if item['grade']>i:
i=item['grade']
n=item['name']
print(i,n)
f.將列表按學(xué)生成績從大到小排序(掙扎一下窃诉,不行就放棄)
t1=[]
t2=[]
t3=[]
for item in t:
t1.append(item['grade'])
t1.sort(reverse=True)
t3=list(set(t1))
for x in t3:
for item2 in t:
if x==item2['grade']:
t2.append(item2)
print(t2)
3.用三個列表表示三門學(xué)科的選課學(xué)生姓名(一個學(xué)生可以同時選多門課)
english=['小張','小明','小王','小馬']
math=['小紅','小馬','小李']
physical=['小紅','小王','小馬','小李']
a. 求選課學(xué)生總共有多少人
print(len(set(english)|set(math)|set(physical)))
b. 求只選了第一個學(xué)科的人的數(shù)量和對應(yīng)的名字
print(len(english))
for name in english:
print(name,end=' ')
print()
c. 求只選了一門學(xué)科的學(xué)生的數(shù)量和對應(yīng)的名字
print(len(set(english)&set(math)&set(physical)),end=' ')
print(''.join(set(english)&set(math)&set(physical)))
d. 求只選了兩門學(xué)科的學(xué)生的數(shù)量和對應(yīng)的名字
set1=set(english)
set2=set(math)
set3=set(physical)
set4=(set1&set2)|(set1&set3)|(set2&set3)
set5=set4-(set1&set2&set3)
print(' '.join(set5))
e. 求選了三門學(xué)生的學(xué)生的數(shù)量和對應(yīng)的名字
print(' '.join(set(english)&set(math)&set(physical)))