text: # Prints the names of graduates along with their average grade across all modules
  #
  # Example input: GraduatesList([[40,50,40,60,40],[50,60,70,80,90]],[0,2],["Robbie","James"])
  
  def CanGraduate(MARKS,COMPULSORY,s):
    PassedAllCompulsoryModules=True
    PassedNonCompulsoryModulesCount=0
    for i in range(len(MARKS[s])):
      grade=MARKS[s][i]
      compulsory=IsCompulsory(i,COMPULSORY)
      if (compulsory):
        # compulsory module
        if (grade < 40):
          PassedAllCompulsoryModules=False
      else:
          # non-compulsory module
        if (grade >= 40):
            PassedNonCompulsoryModulesCount+=1
  
    return PassedAllCompulsoryModules and PassedNonCompulsoryModulesCount >= 3
  
  def IsCompulsory(i,COMPULSORY):
    for j in range(len(COMPULSORY)):
      if (COMPULSORY[j] == i):
        return True;
    return False
  
  def GraduatesList(MARKS,COMPULSORY,NAMES):
    Graduates=[]
    ModuleAverages=[]
    for i in range(len(MARKS)):
      canGrad=CanGraduate(MARKS,COMPULSORY,i)
      if (canGrad):
        name=NAMES[i]
        avg=CalcModAvg(MARKS[i])
        Graduates.append(name)
        ModuleAverages.append(avg)
  
    for j in range(len(Graduates)):
      print(Graduates[j], ModuleAverages[j])
  
  def CalcModAvg(RESULTS):
    grade_sum=0
    for i in range(len(RESULTS)):
      # sum all grades
      grade_sum+=RESULTS[i]
    return grade_sum/len(RESULTS)
  