student_names = []
test1_scores = []
test2_scores = []
test3_scores = []
total_scores = []
total_students = int(input("How many students are in you class? "))
counter = int(0)
while counter < total_students:
student_name = str(input("What is the name of the student %s " % (counter+1)))
if student_name.isalpha() == True:
student_names.append(student_name)
test1_score = int(input("Please enter the score for test 1: "))
if test1_score >= 0 and test1_score <= 20:
test1_scores.append(test1_score)
if student_name.isalpha() == True:
student_names.append(student_name)
test2_score = int(input("Please enter the score for test 2: "))
if test2_score >= 0 and test2_score <= 25:
test2_scores.append(test2_score)
if student_name.isalpha() == True:
student_names.append(student_name)
test3_score = int(input("Please enter the score for test 3: "))
if test3_score >= 0 and test3_score <= 35:
test3_scores.append(test3_score)
counter += 1
total_scores.append(test1_score + test2_score + test3_score)
print ("The total score is %s " %(total_scores))
if total_students == counter:
average = total_scores / (3 * total_students)
print ("The average score is %s " %(average))
如果你看一下我的代码的底部,你可以看到我想把名为total_scores
的数组除以测试分数x学生数,这样我就可以达到学生的平均分数。但我得到以下错误:
average = total_scores / (3 * total_students)
TypeError: unsupported operand type(s) for /: 'list' and 'int'
答案 0 :(得分:0)
你应该遍历total_scores数组:
for score in total_scores:
total += score
average = total/3*total_students