Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 2 9 class count with function
- ''' A list of random 'scores' is generated with a top mark of 'tops'
- and number of learners as 'learners' The list of scores is printed.
- Create a function 'count' which takes a 'mark' and the 'scores' as arguments
- to return the number of 'learners' with that 'mark'.
- Prints the number of 'scorers' with the 'queried score' in the class of 'learners'
- '''
- import random
- def count(mark,scores):
- scorers = 0
- for score in scores:
- if score == mark:
- scorers += 1
- return scorers
- learners = 30
- qscore = 10 # Query the required score. Could use an input here.
- tops = 10 # the value of top score used in the random score generator
- scores = []
- for x in range (0, learners):
- scores.append(random.randint(0, tops))
- print(scores)
- scorers = count(qscore, scores)
- # print(scorers)
- print("{0} learners got {1} marks in the class of {2} learners.".format(scorers, qscore,learners))
Add Comment
Please, Sign In to add comment