{“学号”: “220101”, “姓名”: “张三”, “成绩”: 92}, {“学号”: “220102”, “姓名”: “李四”, “成绩”: 85}, {“学号”: “220103”, “姓名”: “王五”, “成绩”: 70}, {“学号”: “220104”, “姓名”: “陈六”, “成绩”: 60}, {“学号”: “220105”, “姓名”: “钱七”, “成绩”: 80}, {“学号”: “L220106”, “姓名”: “Jessi”, “成绩”: 90}, {“学号”: “L220107”, “姓名”: “Yoon Suk Yeol”, “成绩”: 30}]

清屏函数

def clear(): os.system('cls' if os.name == 'nt' else 'clear')

输入学生成绩

def input_score(): num = input(“请输入学号: ”) name = input(“请输入姓名: ”) score = int(input(“请输入成绩: ”))

# 检查学号是否已存在
for student in students:
    if student[“学号”] == num:
        print(“学号已存在,请重新输入!”)
        return

# 添加学生数据
students.append({“学号”: num, “姓名”: name, “成绩”: score})
print(“添加成功!”)

查询成绩

def query_score(): method = input(“请输入查询方式(1-按学号查询,2-按姓名查询): ”)

if method == “1”:
    num = input(“请输入学号: ”)
    for student in students:
        if student[“学号”] == num:
            print(f“学号: {student['学号']}, 姓名: {student['姓名']}, 成绩: {student['成绩']}”)
            return
    print(“未找到该学生!”)

elif method == “2”:
    name = input(“请输入姓名: ”)
    for student in students:
        if student[“姓名”] == name:
            print(f“学号: {student['学号']}, 姓名: {student['姓名']}, 成绩: {student['成绩']}”)
            return
    print(“未找到该学生!”)

else:
    print(“输入有误,请重新输入!”)

修改成绩

def modify_score(): num = input(“请输入学号: ”) for student in students: if student[“学号”] == num: score = int(input(“请输入新的成绩: ”)) student[“成绩”] = score print(“修改成功!”) return print(“未找到该学生!”)

输出所有学生成绩

def output_scores(): for student in students: print(f“学号: {student['学号']}, 姓名: {student['姓名']}, 成绩: {student['成绩']}”)

统计及格和优秀人数

def count_pass_and_excellent(): pass_count = 0 excellent_count = 0

for student in students:
    if student[“成绩”] >= 60:
        pass_count += 1
    if student[“成绩”] >= 90:
        excellent_count += 1

print(f“及格人数: {pass_count}”)
print(f“优秀人数: {excellent_count}”)

主程序循环

while True: clear() print(“”) print(“学生成绩管理系统”) print(“”) print(“”) print(“1--输入数据”) print(“2--查询成绩******”) print(“3--修改成绩*********************”) print(“4--输出所有学生成绩*************”) print(“5--统计及格和优秀人数***********”) print(“6--退出系统*********************”) print(“0--清屏*************************”) print(“************************************”)

choice = input(“请输入选项: ”)

if choice == “1”:
    input_score()
elif choice == “2”:
    query_score()
elif choice == “3”:
    modify_score()
elif choice == “4”:
    output_scores()
elif choice == “5”:
    count_pass_and_excellent()
elif choice == “6”:
    break
elif choice == “0”:
    clear()
else:
    print(“输入有误,请重新输入!”)

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

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