TonyMo

2_9_class_count_with_function.py

Mar 26th, 2021 (edited)
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. # 2 9 class count with function
  2. ''' A list of random 'scores' is generated with a top mark of 'tops'
  3. and number of learners as 'learners' The list of scores is printed.
  4. Create a function 'count' which takes a 'mark' and the 'scores' as arguments
  5. to return the number of 'learners' with that 'mark'.
  6. Prints the number of 'scorers' with the 'queried score' in the class of 'learners'
  7. '''
  8. import random
  9.  
  10. def count(mark,scores):
  11.     scorers = 0
  12.     for score in scores:
  13.         if score == mark:
  14.             scorers += 1
  15.     return scorers
  16.  
  17. learners = 30
  18. qscore = 10 # Query the required score. Could use an input here.
  19. tops = 10    # the value of top score used in the random score generator
  20.  
  21. scores = []
  22.  
  23. for x in range (0, learners):
  24.   scores.append(random.randint(0, tops))
  25.  
  26. print(scores)
  27.  
  28. scorers = count(qscore, scores)
  29. # print(scorers)
  30.  
  31. print("{0} learners got {1} marks in the class of {2} learners.".format(scorers, qscore,learners))
  32.  
Add Comment
Please, Sign In to add comment