首页 > 解决方案 > 编写一个代码,该代码将平均一个学生的一组成绩并返回该学生的字母成绩

问题描述

该程序将要求平均成绩的数量,然后它将循环接受给定的成绩数量。输入所有分数后,程序将通过将所有分数相加并除以输入的分数数来平均分数(注意:您需要在循环输入时将分数相加。)一旦平均计算后,程序将根据下面提供的比例查看应将哪个字母等级分配给平均值。

有人可以帮我用累加器创建一个循环吗?这是我到目前为止所做的:

Num = int(input("Enter the number of scores: "))

score = int(input("Enter a score: "))

 
Average = (score/Num)

if (Average >= 93):
    print("A")

elif(Average >= 85):
    print("B")
      
elif(Average >= 77):
    print("C")

elif(Average >= 69):
    print("D")
    
elif(Average <= 68):
    print("F")

标签: loopsaveragecomputer-scienceaccumulator

解决方案


我假设您根据您提供的语法在 python 中编写代码。在实际实现它之前,您可以先尝试为它制作一个伪代码。

declaring totalScore = 0
declaring average = 0 
declaring score

# input number of lesson will be counted to enter the score
input numOfLesson

# Looping to enter the score of each student to list
for i in range(numOfLesson):
   input score
   total = total +  score

# you got the total score, and what you have to do is to divide it with numOfLesson
# to get the average 
average = total / numOfLesson

现在您知道如何一步一步地进行操作了,您要做的就是将其转换为代码


推荐阅读