Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- # Add your count function here
- def count(target_grade,scores_list):
- target_hits = 0
- for score in scores_list:
- if score == target_grade:
- target_hits += 1
- return target_hits, target_grade
- # A counting function for a range of values (closed interval)
- def count_range(lower, upper, scores_list):
- cumulative_count = 0
- for x in range(lower, upper+1):
- xcount, xvalue = count(x, scores_list)
- print(xcount, " count of mark ", xvalue)
- cumulative_count = cumulative_count + xcount
- print("cumulative count in range [{0},{1}] > ".format(lower, upper),cumulative_count)
- return cumulative_count
- # "Create" a list of scores, randomly
- scores = []
- for x in range (0, 30):
- scores.append(random.randint(0, 10))
- print("list of scores ", scores)
- # Cumulative or range count function called here
- print("Cumulative or range count function called here:")
- cumulative_count = count_range(4,7, scores)
- print("Sanity check of returned value: ", cumulative_count)
- # Count function called here
- print("Count function called here:")
- target_scorers, target_grade = count(7, scores)
- #print(target_scorers) #sanity check
- #print(target_grade)
- print("{0} learners got mark {1}".format(target_scorers, target_grade ))
Add Comment
Please, Sign In to add comment