Average marks - Python project for beginners (8)

preview_player
Показать описание
We put various test marks of some of students in a list of lists. The number of students and the number of tests can vary. Then we calculate the average mark for each student.

You'll learn most by trying my code while watching the video.

Please post your improvement on my code on the comments.

Concepts:
List of Lists
Nested for loop

Basic Python Fast

Playlist of my Python examples

#pythonprojects #pythonprojectforbeginners #pythonprojectideas #pythonforbeginners #pythonforbeginner
Рекомендации по теме
Комментарии
Автор

More optimize way, can be done with 2 for loops . pl check.
students = [['aa', 85, 90, 75],
['bb', 82, 98, 80],
['cc', 83, 86, 91],
['dd', 89, 90, 76]]
num_of_tests = len(students[0]) - 1
num_students = len(students)
sum_total = 0
for i in range(1, num_of_tests + 1):
for j in range(num_students):
sum_total += students[j][i]
print('The avg for test ', i, ' is ', sum_total / len(students))
sum_total = 0

bharatapar
Автор

using dictionary and class.

class AverageMarksCalculator :

def __init__(self, marks) :
self.marks = marks

def calculat_marks(self) :
student_average_marks = {}

for name, marks in self.marks.items() :
average = 0
for mark in marks :
average += mark
# print(name)
: average})
return student_average_marks

def student_average_marks(self) :
return self.calculat_marks()

student_test = {
'Annie': [85, 90, 75],
'Binnie': [ 82, 98, 80],
'Carol': [83, 86, 91],
'Daris': [89, 90, 76],
}
studetn_1 =

abdulrahmanibraheem