day08字典作业

1.声明一个字典保存一个学生的信息,学生信息中包括: 姓名、年龄、成绩(单科)、电话

student1 = {'name':'阿毛', 'age':20, 'score':60, 'tel':'10086'}
student2 = {'name':'阿建', 'age':18, 'score':60, 'tel':'10088'}
student3 = {'name':'阿苟', 'age':21, 'score':70, 'tel':'1008611'}
student4 = {'name':'阿蛋', 'age':22, 'score':40, 'tel':'10001'}
student5 = {'name':'阿旺', 'age':25, 'score':80, 'tel':'10000'}
student6 = {'name':'阿茶', 'age':16, 'score':90, 'tel':'1010'}

2.声明一个列表,在列表中保存6个学生的信息(6个题1中的字典)

students = [student1, student2, student3, student4, student5, student6]

#a.统计不及格学生的个数
#b.打印不及格学生的名字和对应的成绩
#c.统计未成年学生的个数
#d.打印手机尾号是8的学生的名字
#e.打印最高分和对应的学生的名字
#f.将列表按学生成绩从大到小排序(挣扎一下,不行就放弃)

count_fail = 0  #不及格的学生人数
fail_students = {}  #不及格学生字典
count_underage = 0  #未成年学生人数
tel8_students = []  #尾号为8的学生集合
max_score = 0  #最高分
min_score = 0  #最低分
max_score_student = ''  #最高分学生姓名

for student in students:
    if student['score'] <60:
        fail_students[student['name']] = student['score']
        count_fail += 1
    if student['age'] < 18:
        count_underage += 1
    if student['tel'][-1] == '8':
        tel8_students.append(student['name'])
    if max_score < student['score']:
        max_score = student['score']
        max_score_student = student['name']

print("不及格学生的个数为:", count_fail)
print("不及格的学生是:", fail_students)
print("未成年学生的个数是:", count_underage)
print("手机尾号是8的学生是:", tel8_students)
print("最高成绩是%s同学的%.1f分" % (max_score_student, max_score))

# students.sort(key=lambda x:x['age'])
print("按成绩从小到大排序为:")
for i in range(len(students)-1):
    for j in range(i+1, len(students)-1):
        if students[j]['score']

3.尝试实现学生管理系统的界面(见视频)

home_page = """
=======学生管理系统=======
    1.查看学生信息
    2.添加学生信息
    0.退出
========================
"""

student_info_page = """
========学生信息=========
%s
1. 查看
2. 添加
3. 删除
0. 返回
=======================
"""

change_stu_info = """
=======修改学生信息======


"""

add_student_page = """
=======添加学生==========
请输入学生信息

1. 保存
2. 返回
=======================
"""

students = []   #一个保存所有学生信息的列表

while True:
    print(home_page)    #启动程序时打印学生管理系统首页
    num1 = int(input())     #第一次选择输入num1
    if num1 == 1:
        if students == []:
            print(student_info_page % "暂无学生信息") #没有学生信息时打印默认画面
        else:
            print(student_info_page % students)     #有学生信息时打印
        num2 = int(input())     #第二次选择输入num2
        # if num2 == 1:         #查看某个学生的信息
        #     stu_name = input("请输入你要查看的学生的姓名:")
        #     if stu_name in students
        #     students['姓名'] = input()
        #     students['出生日期'] = input()
        #     students['籍贯'] = input()
        #     students['手机号码'] = input()
        #     students['学号'] = input()
        if num2 == 2:
            print(add_student_page)         #打印添加学生信息页面
            name = input("姓名:")
            birth = input("出生日期:")
            position = input("籍贯:")
            tel = input("手机号码:")
            stu_num = input("学号:")

            print("是否保存")
            save = input()         #输入是否保存
            if save == "是" or "yes":
                student = {"姓名": name, "出生日期": birth, \
                           "籍贯": position, "手机号码": tel, "学号": stu_num}
                students.append(student)
                print("保存成功")
                print("按0返回")
                save = input()
                if save == "0":
                    continue
            else:
                continue
        if num2 == 0:
            continue
    if num1 == 2:
        print(add_student_page)
        student['姓名'] = input("姓名:")
        student['出生日期'] = input("出生日期:")
        student['籍贯'] = input("籍贯:")
        student['手机号码'] = input("手机号码:")
        student['学号'] = input("学号:")
        print("是否保存")
        save = input()
        if save == "是" or "yes":
            student = {"姓名": name, "出生日期": birth, \
                       "籍贯": position, "手机号码": tel, "学号": stu_num}
            students.append(student)
            print("保存成功")
            print("按0返回")
            save = input()
            if save == "0":
                continue
        else:
            continue
    if num1 == 0:
        print("谢谢使用")
        break

你可能感兴趣的:(day08字典作业)