1.声明一个字典保存一个学生的信息,学生信息中包括: 姓名、年龄、成绩(单科)、电话、性别(男、女、不明)
student = {'name':'bluestar', 'age':'18', '成绩':'120', '电话':18882307609, '性别':'男'}
print(student)
2.声明一个列表,在列表中保存6个学生的信息(6个题1中的字典)
a.统计不及格学生的个数
b.打印不及格学生的名字和对应的成绩
c.统计未成年学生的个数
d.打印手机尾号是8的学生的名字
e.打印最高分和对应的学生的名字
f.将列表按学生成绩从大到小排序(挣扎一下,不行就放弃)
g.删除性别不明的所有学生
student = [
{'name': 'bluestar', 'age': '22', '成绩': 80, '电话': 18882307609, '性别': '男'},
{'name': '赵灵儿', 'age': '17', '成绩': 90, '电话': 18888454388, '性别': '女'},
{'name': '李逍遥', 'age': '20', '成绩': 59, '电话': 18121807802, '性别': '男'},
{'name': '王意如', 'age': '19', '成绩': 58, '电话': 11881307609, '性别': '女'},
{'name': '邪剑仙', 'age': '100', '成绩': 36, '电话': 18883213600, '性别': '不明'},
]
n = 0
a = 0
m = 0
for x in student:
if x['成绩'] < 60:
n += 1
print(x['name'], x['成绩'])
if int(x['age']) < 18:
a += 1
if int(x['电话']) % 10 == 8:
print('手机尾号是8的学生名字=', x['name'])
print('未成年学生成绩 =', a)
print('不及格学生人数 =', n)
for x in student:
if x['成绩'] > m:
m = x['成绩']
for x in student:
if x['成绩'] == m:
print('成绩最高学生的名字 =', x['name'])
m1 = 0
for n1 in range(0, len(student)-1):
for m1 in range(m1, len(student)-1):
if student[n1]['成绩'] < student[m1]['成绩']:
i = student[n1]
student[n1] = student[m1]
student[m1] = i
m1 += 1
print(student)
for x in student:
if x['性别'] == '不明':
x.clear()
print(student)
'''
3.用三个列表表示三门学科的选课学生姓名(一个学生可以同时选多门课)
a. 求选课学生总共有多少人
chinese = ['张三', '郑九', '王五', '赵六']
english = ['刘七', '李四', '王五', '赵六']
math = ['张三', '李四', '周八', '赵六']
n = chinese + english + math
print(set(n))
b. 求只选了第一个学科的人的数量和对应的名字
n1 = 0
for x in chinese:
if x not in english and x not in math:
n1 += 1
print(x, n1)
c. 求只选了一门学科的学生的数量和对应的名字
n1, n2, n3 = 0, 0, 0
n1, n2, n3 = 0, 0, 0
for x in chinese:
if x not in english and x not in math:
n1 += 1
print("只选择语文", x)
for y in english:
if y not in chinese and y not in math:
n2 += 1
print("只选择英语", y)
for z in math:
if z not in english and z not in chinese:
n3 += 1
print("只选择数学", z)
print("只选择一科的总人数 = ", n1+n2+n3)
d. 求只选了两门学科的学生的数量和对应的名字
n1, n2, n3 = 0, 0, 0
for x in chinese:
if x in english and x not in math :
n1 += 1
print("选择英语和语文", x)
for y in english:
if y not in chinese and y in math:
n2 += 1
print("只选择英语和数学", y)
for z in math:
if z not in english and z in chinese:
n3 += 1
print("选择语文和数学", z)
print("只选择两科的总人数 = ", n1+n2+n3)
e. 求选了三门学生的学生的数量和对应的名字
n1, n2, n3 = 0, 0, 0
for x in chinese:
if x in english and x in math :
n1 += 1
print("选择三科的学生", x)
print("只选择两科的总人数 = ", n1)