我可以使用一些帮助来解决错误。这是我的代码,它接受多个输入和输出(输入的数量、未参加考试的学生数量、成绩高于 80 的学生、参加考试的学生的平均值以及整个班级,包括那些错过的人。
#number of students who miss, and get a highscore
num_miss = 0
num_high = 0
total = 0
count = 0
#The minimum and maximum values
min_score = 100.00
max_score = 0.0
score = int(input("Enter a Score(-1 to quit): "))
#The loop to test score inputs, and the students who missed or got a high score
while score >-1:
if score >= 80:
num_high += 1
elif score == 0:
num_miss += 1
if score < min_score:
min_score = score
if score > max_score:
max_score = score
score = int(input("Enter a Score(-1 to quit): "))
# an incriment to count the total for average, and the amount of students that took the exam
total += score
count += 1
students = count
#formulas for creating the averages
average = total / count
average2 = total / (count + -num_miss)
#prints grade report with a dashed line under it
print("Grade Report")
print("-" * 38)
if count >= 0:
print("Total number of students in the class: {}".format(students))
print("Number of students who missed the exam: {}".format(num_miss))
print("Number of students who took the exam: {}".format(count - num_miss))
print("Number of students who scored high: {}".format(num_high))
print("Average of all students in the class: {0:.2f}".format(average))
print("Average of students taking the exam: {0:.2f}".format(average2))
这就是问题所在:通过输入所有这些值:65、98、45、76、87、94、43、0、89、80、79、0、100、55、75、0、77、-1 到结束
这就是我的教授得到的输出
成绩报告
1. Total number of students in the class: 17
2.Number of students who missed the exam: 3
3.Number of students who took the exam: 14
4.Numberof students who scored high: 6
5.Average of all students in the class:62.5
6.Average of students taking the exam: 75.9
这就是我得到的输出
成绩报告
1.Total number of students in the class: 17
2.Number of students who missed the exam: 3
3.Number of students who took the exam: 14
4.Number of students who scored high: 6
5.Average of all students in the class: 58.64
6.Average of all students taking the exam: 71.21
我如何修正我的平均成绩,使他们与我的教授一样?