Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.93 KB | None | 0 0
  1. import random
  2.  
  3. #
  4. # Add your count function here
  5. #
  6. def count(mark,scores):
  7.     numberOfOcur = 0
  8.     for i in scores:
  9.         if i == mark:
  10.             numberOfOcur += 1
  11.     return numberOfOcur
  12.  
  13. # This function sums the items of a list.
  14. def sumList(list):
  15.     newsum = 0
  16.     for i in list:
  17.         newsum = newsum + i
  18.     return newsum
  19.  
  20. scores = []
  21.  
  22. for x in range (0, 30):
  23.   scores.append(random.randint(0, 10))
  24.  
  25. print(scores)
  26.  
  27. top_scorers = count(10, scores) # Count function called here
  28. # Define a list in which we have the number
  29. # of occurences with scores less than 5.
  30. # At the beginning we set all to 0.
  31. down_scorers = [0,0,0,0,0]
  32.  
  33. #Count the occurence of the scores and save it in the list.
  34. for i in range(len(down_scorers)):
  35.     down_scorers[i] = count(i,scores)
  36.  
  37.  
  38. print("{0} learners got top marks".format(top_scorers))
  39. print("{0} learners not reached the half of the score.".format(sumList(down_scorers)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement