我需要询问10名学生的最终成绩(而)增加他们的价值:
类似于:
请输入学生1的最终成绩
请输入学生2的最终成绩
依旧......直到10岁
然后我需要得到他们输入的成绩,并找到平均成绩。
这是我到目前为止所做的:
def main():
x = []
for i in range(10):
final_grades = x.append(int(input('Please enter final grade for student: ')))
##average_final_grade = final_grades / 10
##print(average_final_grade)
main()
答案 0 :(得分:1)
# list of grades
x = []
# count of students
n = 10
# fill list with grades from console input
# using pythonic generator
x = [int(input('Please enter final grade for student {}: '.format(i+1))) for i in range(n)]
# count average,
# sum is builtin way to sum values in list
# float required for python 2.x to make avg float, not int
average_final_grade = sum(x) / float(n)
print('Avg grade is {}'.format(average_final_grade))
答案 1 :(得分:1)
首先,您需要像以前一样获取值:
x = []
for i in range(10):
x.append(int(input('Please enter final grade for student: ')))
现在您需要对x
:
total_sum = sum(x)
然后,你得到平均值:
average_final_grade = total_sum/len(sum)
答案 2 :(得分:0)
total=sum(x)
average=total/10
print(average)