python第二周day3(9.24)
1、day7字典作业更改版
students = [
{
'name': '晨晨', 'age':18, 'score': 78, 'tel': '123', 'gender': '男'},
{
'name': '陈来', 'age':20, 'score': 80, 'tel': '321', 'gender': '不明'},
{
'name': '陈昕', 'age':28, 'score': 98, 'tel': '653', 'gender': '女'},
{
'name': '小新', 'age':32, 'score': 65, 'tel': '783', 'gender': '男'},
{
'name': '小明', 'age':17, 'score': 24, 'tel': '988', 'gender': '女'},
{
'name': '小红', 'age':14, 'score': 54, 'tel': '903', 'gender': '男'}
]
count = 0
for stu in students:
if stu['score'] < 60:
count += 1
print('1)不及格学生的个数:', count)
print('2)不及格学生的名字和对应的成绩')
for stu in students:
score = stu['score']
if score < 60:
print(stu['name'], score)
print('4)手机尾号是8的学生的名字:')
for stu in students:
if stu['tel'][-1] == '8':
print(stu['name'])
for stu in students:
if int(stu['tel']) % 10 == 8:
print(stu['name'])
print('5)最高分和对应的学生的名字:')
max_score = students[0]['score']
for stu in students[1:]:
score = stu['score']
if score > max_score:
max_score = score
for stu in students:
if stu['score'] == max_score:
print(stu['name'], max_score)
max_score = students[0]['score']
names = [students[0]['name']]
for stu in students[1:]:
score = stu['score']
if score == max_score:
names.append(stu['name'])
elif score > max_score:
max_score = score
names.clear()
names.append(stu['name'])
print(names, max_score)