loops - 编写一个代码,该代码将平均一个学生的一组成绩并返回该学生的字母成绩
问题描述
该程序将要求平均成绩的数量,然后它将循环接受给定的成绩数量。输入所有分数后,程序将通过将所有分数相加并除以输入的分数数来平均分数(注意:您需要在循环输入时将分数相加。)一旦平均计算后,程序将根据下面提供的比例查看应将哪个字母等级分配给平均值。
有人可以帮我用累加器创建一个循环吗?这是我到目前为止所做的:
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")
解决方案
我假设您根据您提供的语法在 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
现在您知道如何一步一步地进行操作了,您要做的就是将其转换为代码
推荐阅读
- k-means - k表示算法如何实现颜色压缩
- python - 在 KerasRegressor 上使用交叉验证时,如何获取不同拟合的历史记录?
- azure - 更改带有备份的 Azure 资源组
- javascript - 复选框不会检查,但每个复选框都在注册第一次点击并将数据发送到服务器
- version - 如何处理预生产的项目版本控制?
- c# - ASP.NET 和 C#:其余的客户端 url 存储在哪里?
- sql - 从 PowerApps 写回 Oracle
- html - 如何向 .class:not(:hover) 添加过渡?
- typescript - 如何在使用 NavigationStackScreenComponent 类型注释对屏幕组件进行类型检查时合并组件道具的类型注释?
- angular - 我应该如何在 Angular 中正确设置这个属性?