JDog - 2 months ago 5

Python Question

I need to ask the final grade of 10 students (**while**) incrementing their values:

So something like:

Please enter final grade for student 1

Please enter final grade for student 2

and so on... till 10

Then I need to get the grades they entered, and find average.

This is what I have so far:

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

Answer

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

Source (Stackoverflow)

Comments