以下是一个简单的学生成绩管理系统的设计:

import os

def clear_screen():
    os.system('clear')  # 清屏命令,根据操作系统不同可能需要修改

def input_data(students):
    student_id = input("请输入学生学号:")
    name = input("请输入学生姓名:")
    score = float(input("请输入学生成绩:"))
    students[student_id] = {'name': name, 'score': score}
    print("学生信息输入成功!")
    input("按任意键继续...")
    clear_screen()

def query_score(students):
    option = input("请选择查询方式(1-按学号查询,2-按姓名查询):")
    if option == '1':
        student_id = input("请输入学生学号:")
        if student_id in students:
            print("学生姓名:", students[student_id]['name'])
            print("学生成绩:", students[student_id]['score'])
        else:
            print("学生不存在!")
    elif option == '2':
        name = input("请输入学生姓名:")
        found = False
        for student_id, student in students.items():
            if student['name'] == name:
                print("学生学号:", student_id)
                print("学生成绩:", student['score'])
                found = True
        if not found:
            print("学生不存在!")
    else:
        print("无效的选项!")
    input("按任意键继续...")
    clear_screen()

def modify_score(students):
    student_id = input("请输入学生学号:")
    if student_id in students:
        new_score = float(input("请输入新的学生成绩:"))
        students[student_id]['score'] = new_score
        print("学生成绩修改成功!")
    else:
        print("学生不存在!")
    input("按任意键继续...")
    clear_screen()

def list_scores(students):
    print("学号\t姓名\t成绩")
    for student_id, student in students.items():
        print(student_id, "\t", student['name'], "\t", student['score'])
    input("按任意键继续...")
    clear_screen()

def count_pass_excellent(students):
    pass_count = 0
    excellent_count = 0
    for student in students.values():
        if student['score'] >= 60:
            pass_count += 1
        if student['score'] >= 90:
            excellent_count += 1
    print("及格人数:", pass_count)
    print("优秀人数:", excellent_count)
    input("按任意键继续...")
    clear_screen()

def main():
    students = {
        '220101': {'name': '张三', 'score': 92},
        '220102': {'name': '李四', 'score': 85},
        '220103': {'name': '王五', 'score': 70},
        '220104': {'name': '陈六', 'score': 60},
        '220105': {'name': '钱七', 'score': 80},
        'L220106': {'name': 'Jessi', 'score': 90},
        'L220107': {'name': 'Yoon Suk Yeol', 'score': 3}
    }

    while True:
        print("************************************")
        print("学生成绩管理系统")
        print("************************************")
        print("************************************")
        print("**1--输入数据***********************")
        print("**2--查询成绩***********************")
        print("**3--修改成绩***********************")
        print("**4--输出所有学生成绩***************")
        print("**5--统计及格和优秀人数*************")
        print("**6--退出系统***********************")
        print("**0--清屏***************************")
        print("************************************")
        option = input("请输入选项:")
        if option == '1':
            input_data(students)
        elif option == '2':
            query_score(students)
        elif option == '3':
            modify_score(students)
        elif option == '4':
            list_scores(students)
        elif option == '5':
            count_pass_excellent(students)
        elif option == '6':
            break
        elif option == '0':
            clear_screen()
        else:
            print("无效的选项!")
            input("按任意键继续...")
            clear_screen()

main()

该系统使用一个字典students存储学生的学号为键,学生信息(姓名和成绩)为值。通过不同的选项,用户可以进行数据输入、查询、修改、输出、统计等操作。程序通过一个无限循环来保持系统的运行,直到用户选择退出系统


原文地址: http://www.cveoy.top/t/topic/hOz6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录