python输入10个学生的成绩储存在列表中_获得10名学生的平均成绩python
我有一個程序,要求用戶輸入一個學生的網絡ID,然后他們在5個作業(yè)中的成績加上他們在期中和期末考試中得到的分數。然后將它們相加和除以得到學生的平均成績,并以表格形式顯示。在
我需要做的是,將整個過程循環(huán)9次。所以本質上,我會要求9個以上的學生輸入相同的內容,然后需要以表格的形式顯示出來。在
我的問題是,我如何循環(huán),我現(xiàn)在有'x'的次數,然后顯示所有學生的平均值。在
這是我現(xiàn)在的代碼:# x holds the list of grades
x = []
# count of assignments
assignments = 5
# Ask for a student ID from user
NETID = int(input('Enter your 4 digit student NET ID: '))
# fill list with grades from console input
x = [int(input('Please enter the grade you got on assignment {}: '.format(i+1))) for i in range(assignments)]
midTermGrade = int(input('Please enter the grade you got on you Mid-Term: '))
finalGrade = int(input('Please enter the grade you got on you Final: '))
# count average,
average_assignment_grade = (sum(x) + midTermGrade + finalGrade) / 7
print()
print('NET ID \t Average Final Grade')
print('---------------------------------')
for number in range(1):
print(NETID, '\t\t', format(average_assignment_grade, '.1f'),'%')
main()
在控制臺上是這樣的:
總結
以上是生活随笔為你收集整理的python输入10个学生的成绩储存在列表中_获得10名学生的平均成绩python的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql数据库挂科_面试命中率 90%
- 下一篇: mysql safe无法启动_解决mys