dict0 = {}
dict0['name']='双儿'
dict0['age'] = '18'
dict0['score'] = '0'
dict0['电话号码'] = '11112222333'
print(dict0)
声明一个列表保存6个人的信息
list1 = [
{'name': '双儿', 'age': '11', 'score': '0', '电话号码': '11112222338'},
{'name': '双儿1', 'age': '13', 'score': '30', '电话号码': '11112222333'},
{'name': '双儿2', 'age': '12', 'score': '70', '电话号码': '11112222338'},
{'name': '双儿3', 'age': '15', 'score': '50', '电话号码': '11112222333'},
{'name': '双儿4', 'age': '18', 'score': '80', '电话号码': '11112222338'},
{'name': '双儿5', 'age': '18', 'score': '90', '电话号码': '11112222333'}]
print(list1)
a.统计不及格学生的个数\
b.打印不及格学生的名字和对应的成绩
count = 0
for dict in list1:
if int(dict['score'])< 60 :
count += 1
print(dict['name'],dict['score'])
print('不及格',count)
c.统计未成年学生的个数
count1 = 0
for dict in list1:
if int(dict['age']) < 18:
count1 += 1
print('未成年',count1)
d.打印手机尾号是8的学生的名字
count2 = 0
for dict in list1:
if int(dict['电话号码'][-1]) == 8:
count2 += 1
print('尾数8',count2)
# e.打印最高分和对应的学生的名字
list2 = []
for dict in list1:
list2.append(int(dict['score']))
print(list2)
num = max(list2)
for dict in list1:
if int(dict['score']) == num:
print(dict['name'],dict['score'])
f.将列表按学生成绩从大到小排序(挣扎一下,不行就放弃)
3.用三个列表表示三门学科的选课学生姓名(一个学生可以同时选多门课)
chinese = ['小米','小花','小明']
math = ['小米','小川','小柴']
english = ['小米','小柴','小双']
a. 求选课学生总共有多少人
count0 = 0
list1 = list(set(chinese)|set(math)|set(english))
for name in list1:
count0 += 1
print(count0)
b. 求只选了第一个学科的人的数量和对应的名字
list2 = list((set(chinese)&set(math))|(set(math)&set(english)))
print(list2)
for name1 in list2:
for name2 in chinese:
if str(name1) == str(name2):
print(set(str(name1)))