fork download
  1. def calculate_GWA(courses):
  2. GPA = 0.0
  3. units = 0.0
  4. for x in courses:
  5. if(x[2]== 'INC' or x[2]=='P' or x[2]=='F' or x[2]=='') or x[1].startswith('('):
  6. continue
  7. else:
  8. units += float(x[1])
  9. GPA += float(x[1])*float(x[2])
  10. if(GPA == 0 or units == 0):
  11. return ''
  12. else:
  13. return round(GPA/units,2)
  14.  
  15. my_grades_2 = [
  16. ('CS 298', '3.0', ''),
  17. ('CS 390', '3.0', '1.25'),('CS 390', '(3.0)', '5.0'),('CS 390', '3.0', '1.0'),('CS 390', '1.0', '1.25'),('CS 390', '10.0', '5'),('CS 390', '3.0', 'P'),('CS 390', '3.0', 'F'),('CS 390', '3.0', '')
  18. ]
  19.  
  20. gwa = calculate_GWA(my_grades_2)
  21. print(gwa) # must output 1.25
Success #stdin #stdout 0.02s 9176KB
stdin
Standard input is empty
stdout
3.41