编写一个Python程序来模拟给定课程中N名学生的期末考试成绩。用户将提供N的值。仅打印成绩的分布,有多少学生获得A,B,C,D和F。
修改#1中的程序,以对N个学生运行该程序M次。 M次后,为每个字母等级打印累计平均值。用户将提供M的值。
作为班级实验任务的一部分,我最终承担了以下责任:
#2 NEED Cumulative Average(#1 modified to run M number of times)
import random
N = int(input("Please enter the number of students:"))
M = int(input("How many times would you like to run this?"))
tries = 0
countF = 0
countD = 0
countC = 0
countB = 0
countA = 0
while tries != M:
tries = tries + 1
for i in range (N):
score = random.randint(30,100)
if score <= 50:
grade = "F"
countF = countF + 1
elif score <=69:
grade = "D"
countD = countD + 1
elif score <= 79:
grade = "C"
countC = countC + 1
elif score <= 89:
grade = "B"
countB = countB + 1
else:
grade = "A"
countA = countA + 1
print(countF, countD, countC, countB, countA)
虽然此程序在#1上可以正常工作,但我很难确定#2的累积平均值的编码。诚然,我的数学缺乏,所以我可能看不到简单的答案。任何帮助表示赞赏。 谢谢。