Day8-Python-作业学生管理系统-2019/01/03

all_students = [
    {'name': 'stu1', 'age': 19, 'score': 81, 'tel': '192222'},
    {'name': 'stu2', 'age': 29, 'score': 90, 'tel': '211222'},
    {'name': 'stu3', 'age': 12, 'score': 67, 'tel': '521114'},
    {'name': 'stu4', 'age': 30, 'score': 45, 'tel': '900012'},
]

1.添加学生:输入学生信息,将输入的学生的信息保存到all_students中

message = input('请输入指令:')
student = {}
if message == '添加学生':
    name = input('姓名:')
    student['name'] = name
    age = int(input('年龄:'))
    student['age'] = age
    score = int(input('成绩:'))
    student['score'] = score
    tel = input('电话:')
    student['tel'] = tel
    all_students.append(student)
print(all_students)

2.按姓名查看学生信息

message = input('请输入指令:')
if message == '查看学生信息':
    count = 0
    name = input('请输入学生姓名:')
    for student in all_students:
        count += 1
        for value in student.values():
            if name == value:
                print(all_students[count-1])

3.求所有学生的平均成绩和平均年龄

message = input('请输入指令:')
if message == '求所有学生的平均成绩':
    scores = []
    count = 0
    for student in all_students:
        scores.append(student['score'])
        count += 1
    print('所有学生的平均成绩是:%.2f' % (sum(scores) / count))
if message == '求所有学生的平均年龄':
    ages = []
    count = 0
    for student in all_students:
        ages.append(student['age'])
        count += 1
    print('所有学生的平均年龄是:%.2f' % (sum(ages) / count))

4.删除班级中年龄小于18岁的学生

count = 0
for student in all_students:
    if student['age'] >= 18:
        count += 1
    else:
        del all_students[count]
print(all_students)

5.统计班级中不及格的学生的人数

count = 0
for student in all_students:
    if student['score'] < 60:
        count +=1
print('不及格的人数是:%d人' % (count))

6.打印手机号最后一位是2的学生的姓名

tels = []
names = []

for student in all_students:
    count = 0
    names.append(student['name'])
    tels.append(student['tel'])
for tel in tels:
    if tel[-1] == '2':
        print(names[count])
        count += 1
    else:
        count += 1

学生管理系统

jieMian = """
===========================================
❀❀欢迎用户:

    ❤ 1.  添加学生
    ❤ 2.  查看学生
    ❤ 3.  修改学生信息
    ❤ 4.  删除学生
    ❤ 5.  返回
============================================
"""
all_students = []
count = 0
print(jieMian)
message = int(input('请选择(1-5):'))
while True:
    if message == 1:
        student = {}
        input_name = input('请输入学生姓名:')
        input_age = int(input('请输入学生年龄:'))
        input_tel = int(input('请输入学生电话:'))
        student['姓名'] = input_name
        student['年龄'] = input_age
        student['电话'] = input_tel
        all_students.append(student)
        print('添加成功!')
        print('1.继续')
        print('2.返回')
        message = int(input('请选择(1-2):'))
        if message == 2:
            print(jieMian)
            message = int(input('请选择(1-5):'))
    if message == 2:
        print('1.查看所有学生')
        print('2.按姓名查找')
        print('3.按学号查找')
        print('4.返回')
        message = int(input('请选择(1-4):'))
        if message == 1:
            for student in all_students:
                name = student['姓名']
                age = student['年龄']
                tel = student['电话']
                count += 1
                print('学号:' + 'stu' + str(count).zfill(3) + ' ' + '姓名:' + name + ' ' + '年龄:' + str(age) + ' ' + '电话:' + str(tel))
            print('1.查看所有学生')
            print('2.按姓名查找')
            print('3.按学号查找')
            print('4.返回')
            message = int(input('请选择(1-4):'))
        if message == 4:
            print(jieMian)
            message = int(input('请选择(1-5):'))
    if message == 3:
        print('1.')
        print('2.')
        print('3.')
        print('4.')
        message = int(input('请选择(1-4):'))
    if message == 4:
        print('1.')
        print('2.')
        print('3.')
        print('4.')
        message = int(input('请选择(1-4):'))
    if message == 5:
        exit()

你可能感兴趣的:(Day8-Python-作业学生管理系统-2019/01/03)