bobhig

average function

Feb 9th, 2019
85
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Average Function
  2. # Output formatted to 2 decimal places
  3.  
  4. import random
  5.  
  6.  
  7. def average(data):
  8.     total = 0
  9.     count = 0
  10.     for item in data:
  11.         total = total + int(item)
  12.         count += 1
  13.    
  14.     return (total/count)
  15.  
  16.  
  17. scores = []
  18.  
  19. for x in range (0, 30):
  20.   scores.append(random.randint(0, 10))
  21.  
  22.  
  23. print("Average mark = %.2f" % average(scores))
RAW Paste Data