1.声明一个字典保存一个学生的信息,学生信息中包括: 姓名、年龄、成绩(单科)、电话、性别(男、女、不明)
students = [
{
'name':'张三',
'age':'14',
'score':'86',
'tel':'1593462135',
'sex':'man'
}
2.声明一个列表,在列表中保存6个学生的信息(6个题1中的字典)
a.统计不及格学生的个数
b.打印不及格学生的名字和对应的成绩
c.统计未成年学生的个数
d.打印手机尾号是8的学生的名字
e.打印最高分和对应的学生的名字
f.将列表按学生成绩从大到小排序(挣扎一下,不行就放弃)
students = [
{
'name':'张三',
'age':14,
'score':86,
'tel':'1593462135',
'sex':'man'
},
{
'name': '李四',
'age': 15,
'score': 96,
'tel': '15698563489',
'sex': 'man'
},
{
'name': '小尾',
'age': 13,
'score': 99,
'tel': '15696413325',
'sex': '不明'
},
{
'name': '小昵',
'age': 16,
'score': 100,
'tel': '15696465468',
'sex': 'woman'
},
{
'name': '小馨',
'age': 13,
'score': 100,
'tel': '15165448325',
'sex': 'woman'
},
{
'name': '男主',
'age': 15,
'score': 59,
'tel': '15866625398',
'sex': 'man'
}
]
low_count = 0
age_count = 0
max_score = 0
scores = []
for student in students:
if student['score']<60:
low_count += 1
print('不及格的'+student['name']+'分数:'+str(student['score']))
if student['age'] < 18:
age_count +=1
if student['tel'][-2] == 8:
print(student['name'])
if student['score']> max_score:
max_score = student['score']
scores.append(student['score'])
print('不及格个数:'+str(low_count))
print('未成年个数:'+str(age_count))
print('成绩排序是:'+str(sorted(scores)))
for student in students:
if student['score'] == max_score:
print('最高分是'+str(max_score)+'名字是:'+student['name'])
g.删除性别不明的所有学生
3.用三个列表表示三门学科的选课学生姓名(一个学生可以同时选多门课)
a. 求选课学生总共有多少人
b. 求只选了第一个学科的人的数量和对应的名字
c. 求只选了一门学科的学生的数量和对应的名字
d. 求只选了两门学科的学生的数量和对应的名字
e. 求选了三门学生的学生的数量和对应的名字
ist_math = ['男反1','女主','后宫2','后宫3']
list_english = ['女主','后宫2','后宫3']
list_chinese = ['男主','女主','后宫2','后宫3','男反1']
a = set(list_math)
b= set(list_chinese)
c = set(list_english)
set1 = a|b|c
print('选课总人数:',len(set1))
set2 = set1 - a -b
print(len(set2),set2)
set3 = set2|(set1-b-c)|(set1-a-c)
print(len(set3),set3)
set4 = set1-set3-(a&b&c)
print(len(set4),set4)
set5 = a&b&c
print(len(set5),set5)