Home > Software engineering >  How can I print the name of students with more than 50 points in all DS?
How can I print the name of students with more than 50 points in all DS?

Time:12-31

I have a several lists and dictionaries showing student names and scores.

How can I print the number of students and their names who have more than 50 points in all DS ?

students = ['Sara', 'Zineb', 'Mohamed', 'Ali', 'Khadija',
            'Idriss', 'Najat', 'Nadia', 'Marouane', 'Ahmed']

scores = {'DS': [[36, 58, 46, 96, 9, 82, 83, 66, 35, 47],
                 [46, 50, 55, 21, 22, 76, 51, 90, 96, 48],
                 [56, 54, 53, 17, 31, 74, 11, 53, 98, 67],
                 [77, 38, 8, 74, 39, 39, 52, 66, 38, 86],
                 [93, 21, 7, 33, 10, 97, 48, 96, 24, 7],
                 [97, 98, 95, 75, 64, 9, 48, 51, 45, 82]],

          'TP': [[48, 63, 98, 47, 25, 90, 100, 21, 41, 44],
                 [73, 79, 78, 39, 11, 100, 57, 96, 13, 99]]}

CodePudding user response:

There are 10 students, and the there are 10 integers in each DS list.

If we want a set of students who scored more than 50 on each: we can (1) create a set of all students, (2) iterate over the lists, and (3) discard students from the set if they scored less than 50. (4) The remaining value in the set tells us that one student ('Nadia') scored more than 50 on all:

more_than_50 = set(students)

for score_list in scores['DS']:
    for student, score in zip(students, score_list):
        if score < 50:
            more_than_50.discard(student)

print(len(more_than_50), more_than_50)
1 {'Nadia'}

CodePudding user response:

You can try with this simple methods :

for i in len(students):
  count=0 
  for row in scores['DS']:
    if row[i]>50:
     count =1 
  if count==len(scores):#if all the grades > 50
    print(students [i])
  • Related