David - 4 months ago 28

Python Question

I have a program that asks a user to enter a Student NETID and then what grades they got on 5 assignments plus the grade they got on the mid-term and final. It then adds them and divides to get that students average grade which displays in table format.

What I need to do, is loop through that whole process 9 more times. So essentially, Ill be asking 9 more students the same input, which then Ill need to display in the table format.

My question is how would I loop through the process that I have right now 'x' amount of times, then display the average of all students.

This is my code right now:

`# 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()

And this is how it looks on console:

Answer

You really did the hardest part. I don't see why you couldn't so the loop of the average. Anyway:

```
student_count = 5;
A = [student_count]
for id_student in range(student_count):
print("STUDENT #", id_student+1)
# 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 | Average Final Grade')
print('---------------------------------')
for number in range(1):
print(NETID, " | ", format(average_assignment_grade, '.1f'),'%')
A.append(average_assignment_grade);
grades_sum = sum(A)
grades_average = grades_sum / 5;
print("SUM OF ALL STUDENTS = " + grades_sum)
print("AVERAGE OF ALL STUDENTS = " + grades_average)
```

**Update:** As suggested above, you should make a function for a single student and loop through that function in another, since SO is not a coding service I won't do that for you, but I think you got the idea.