Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1.  
  2. #!/usr/bin/env python -tt
  3. """ File: avgTest.py """
  4.  
  5.  
  6. def calAverage(testScores):
  7. """Summary line: Computes the average of a group of integers.
  8. Description: This program will takes a group of integers seperated
  9. by commas and return the average of the values.
  10. """
  11.  
  12. examSum = sum(testScores)
  13. return (examSum / len(testScores))
  14.  
  15.  
  16.  
  17.  
  18. if __name__ == '__main__':
  19. """Summary line: Computes the average of a group of integers.
  20. Description: This program will takes a group of integers seperated
  21. by commas and return the average of the values. The input string is
  22. split based on comma, than has the null chars removed. The list of
  23. numbers is then passed to calAverage to create the average.
  24. """
  25.  
  26. null_Chars = ['', ' ']
  27.  
  28.  
  29. print "\nThis program computes the average of three exam scores."
  30. examScores = raw_input('Enter the scores seperated by commas (ex 5,2,1):')
  31.  
  32. examScores = [x for x in examScores.split(',') if x not in null_Chars]
  33.  
  34. print "%.2f" % calAverage([float(x) for x in examScores])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement