You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

字典遍历问题:学生成绩统计程序调试与需求实现

问题排查与需求实现
  • 排查点:当前for循环仅遍历字典第一个元素,未按字典中每个列表的对应索引进行遍历
  • 需求:基于student_grades字典,使用keys()/values()/items()方法完成以下统计:
    1. 打印总分占比最高的学生姓名及成绩占比
    2. 计算每个作业的平均分
    3. 对每位学生总分进行曲线调整,使最优学生总分占比为100%

用户代码

student_grades = {
    'Tricia': [99, 92, 95, 89, 99],
    'Andrew': [56, 79, 90, 22, 50],
    'Nisreen': [88, 62, 68, 75, 78],
    'Alan': [95, 88, 92, 85, 85],
    'Chang': [76, 88, 85, 82, 90]    
}

highest = 0
score = 0
for student, grades in student_grades.items():    
    percent = sum(grades)/len(grades)    
    if percent >= highest:
        highest = percent
        print('Student with Highest total points:')
        print(student, ':', highest)
        print()
        print('Average for each assignment:')
        i = 0
        for i in range(len(grades)):
            score += grades[i] #FIX ME
            print('Assignment', i+1, ':', score / len(grades))        
        print()
        print('Curve:')
    curve = percent / highest 
    print(student, ':', round((curve * 100), 1))

当前输出

Student with Highest total points:
Tricia : 94.8

Average for each assignment:
Assignment 1 : 19.8
Assignment 2 : 38.2
Assignment 3 : 57.2
Assignment 4 : 75.0
Assignment 5 : 94.8

Curve:
Tricia : 100.0
Andrew : 62.7
Nisreen : 78.3
Alan : 93.9
Chang : 88.8

期望的作业平均分

Assignment 1 : 82.8
Assignment 2 : 81.8
Assignment 3 : 86
Assignment 4 : 70.6
Assignment 5 : 80.4

内容的提问来源于stack exchange,提问作者Sarah

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 11:40:52