Question
In python I need to know how to : Add Median Score Function >>> Add a function get_median_score() to calculate the median (Links to an
In python I need to know how to :
Add Median Score Function
>>> Add a function get_median_score() to calculate the median (Links to an external site.) score (see link for calculation), where:
- Single list parameter
- Guardian code
- Use isinstance() to validate parameter is a list, print 'List argument expected' if parameter not a list, and return -1
- If list is empty return 0
- If list only contains a single element, return that value as the median
- If the list contains even number of elements, average the two middle values as the median
- Remember to account for the fact that 0 elements might indicate the number of elements is even if you use the modulus operator, so make sure you have elements in the list as well
- If the list contains an odd number of elements, the middle element is the median score
- Return the median score
>>> Save and run the program, and test the median score function.
Print Grade Range Counts
Typical grading is as follows:
- A: 90+
- B: 80 - 89
- C: 70 - 79
- D: 60 - 69
- F:
Add two functions that will enable you to output the number of A's, B's, C's, D's and F's based on the scores.
>>> Add function count_range() to count the number of scores within a low and high range, where:
- List parameter, low score, high score
- Guardian code
- Use isinstance() to validate parameter is a list, print 'List argument expected' if parameter not a list, and return -1
- If start or end are not integers, print 'start and end must be integers' and return -1
- If start > end or start == end, print 'start must be and return -1
- If list is empty return 0
- Count the number of integers within the start and end range (use >= and
- Return the number of integers within the start and end range
>>> Save and run the program, and test the range count function.
>>> Add function list_range() to call count_range() with ranges appropriate to produce a list of the A, B, C, D and F grades and print out results similar to the image below.
Here is what I got so far:
# import random numbers
import random
def gen_random_integer_list(num, start_range = 1, end_range = 100, sort_list = 'N'): # get random integer list # num = number of integers in list # start_range & end_range = range of integers allowed # sort_list: if Y sort list, if N do not sort #return variable t = [] # test if parameters are valid if num 0') # make sure number is integer elif not isinstance(num, int): print('num must be an integer') # make sure range uses integers elif not isinstance(start_range, int) or not isinstance(end_range, int): print('start_range and end_range must be integers')
else: for i in range(num): r = random.randint(start_range, end_range) t.append(r)
if sort_list.upper() == 'Y': t.sort() # return the list return t
def get_high_score(t): if not isinstance(t, list): print ('List argument expected') elif len (t) > 0: new_t = t[:] new_t.sort() high_score = new_t[-1]
return high_score
def get_low_score(t): if not isinstance(t, list): print ('List argument expected') elif len (t) > 0: new_t = t[:] new_t.sort() low_score = new_t[0]
return low_score
def average_score(t): if not isinstance(t, list): print ('List argument expected') elif len (t) > 0: new_t = t[:] average_score = sum(t)/len(t)
return average_score
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started