Average Grades


SUBMITTED BY: Guest

DATE: Oct. 7, 2012, 2:09 a.m.

FORMAT: Python

SIZE: 1.0 kB

HITS: 1410

  1. #avgGrades
  2. import re
  3. import sys
  4. args = sys.argv[1:]
  5. line = ""
  6. #sys.stdout.write(repr(sys.argv))
  7. for x in args:
  8. line = line + " " + x
  9. if line == "":
  10. sys.stdout.write("0.0")
  11. else:
  12. grades = re.findall("\\d+\.\\d+|\\d+", line)
  13. if len(grades) <= 0:
  14. sys.stdout.write("0.0")
  15. else:
  16. #sys.stdout.write("i'm here!")
  17. average = 0.0
  18. gradeTotal = 0.0
  19. index = 0
  20. totalWeight = 0.0
  21. for grade in grades:
  22. g = float(grade)
  23. weight = 1.0
  24. if index == len(grades)-1:
  25. weight = 1.5
  26. gradeTotal = gradeTotal + (g*weight)
  27. totalWeight = totalWeight + weight
  28. index = index + 1
  29. average = gradeTotal / totalWeight
  30. #print("Avg=",gradeTotal,"/",totalWeight)
  31. #sys.stdout.write("i'm here! ")
  32. sys.stdout.write(str(average))

comments powered by Disqus