【问题标题】:Write a code that will average a set of grades for a student and return the letter grade for that student编写一个代码,该代码将平均一个学生的一组成绩并返回该学生的字母成绩
【发布时间】:2020-10-19 03:03:58
【问题描述】:

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

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

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")

【问题讨论】:

    标签: loops average computer-science accumulator


    【解决方案1】:

    我假设您根据您提供的语法在 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
    

    现在你知道如何一步一步地做,你要做的就是把它转换成代码

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-19
      • 2017-06-10
      • 2021-01-16
      • 1970-01-01
      相关资源
      最近更新 更多