missing = 0
highscore = 0
inclass = 0
takenexam = 0
count = 0
total = 0
minGrade = 100 #assuming 100 is the highest grade possible.
maxGrade = 0
score = int(input("Enter a score (-1 to quit): "))
while score > -1 :
if score >= 80 :
highscore = highscore + 1
if score == 0 :
missing = missing + 1
if 0 <= score <= 100 :
inclass = inclass + 1
if 0 < score <= 100 :
takenexam = takenexam + 1
# Determine if the score is the min or max score.
if score < minGrade :
minGrade = score
if score > maxGrade :
maxGrade = score
# Add the grade to the running total
total = total + score
count = count + 1
# Read the next grade.
score = int(input("Enter a score (-1 to quit): "))
# Print the results.
if count > 0 :
average = total / count
print("number of students in the class: ", inclass)
print("number of students who missed the exam: ", missing)
print("number of students who took the exam: ", takenexam)
print("number of students who scored high: ", highscore)
print("The average of all students in the class %.2f" % average)
これは私が現在コーディングしている方法です。これがセンテニアル制御ループを満たすのにどのように役立つか、また、試験を受けるすべての学生の平均を追加する方法に興味がありました。