Question

# q10 - create function meanMedianMax() to meet the conditions below # - accept a list...

# q10 - create function meanMedianMax() to meet the conditions below
# - accept a list of numeric values
# - add a docstring
# --- Compute the mean (average), median, and maximum of the values in the
# --- list. The mean is the average. The max is the largest value.
# --- The median is the value at the halfway point. If there are an even
# --- number of values in the list, the median is the average of the
# --- two middle numbers.
# - Hint: Both median and maximum are much easier if you sort the list
#
# - return a tuple of the mean, median and max values
#
# - RESTRICTIONS: You are not allowed to use built in max() function
#
# - params: list (of numeric values)
# - return: tuple (of three numeric values)

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def meanMedianMax(lst):
    '''
        Compute the mean (average), median, and maximum of the values in the
        list. The mean is the average. The max is the largest value.
        The median is the value at the halfway point. If there are an even
        number of values in the list, the median is the average of the
        two middle numbers.
    '''
    lst.sort()
    median = None
    if (len(lst) % 2 == 1):
        median = lst[len(lst) // 2]
    else:
        median = (lst[len(lst) // 2 - 1] + lst[len(lst) // 2]) / 2
    maxValue = lst[-1]
    avg = 0
    for x in lst:
        avg += x
    avg = avg / len(lst)
    return (avg, median, maxValue)
Add a comment
Know the answer?
Add Answer to:
# q10 - create function meanMedianMax() to meet the conditions below # - accept a list...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple

    1 write a Python function that takes in a list of integers and returns maximum and minimum values in the list as a tuple. Hint (can be done in one pass, you are not allowed to use built-on min and max functions.)max, min = find_max_min(my_list):2 write a Python function that takes in a list of integers (elements), and an integer number (num). The functions should count and return number of integers in elements greater than, less than, and equal to...

  • ***NEED SOLUTION IN PYTHON *** 1. Create a main function which only gets executed when the...

    ***NEED SOLUTION IN PYTHON *** 1. Create a main function which only gets executed when the file is directly executed Hint: def main(): pass if __name__ == '__main__': main() 2. Your programs will use a file called scores.txt to store a bunch of user-provided numbers. These can be int or float but their values must be between 0 and 100. Inside the main function, display the current list of numbers to the user and ask if they want to update...

  • PYTHON. Write the following functions without using any predefined functions unless specified. def min (dataList) :      ...

    PYTHON. Write the following functions without using any predefined functions unless specified. def min (dataList) :       #returns the smallest value of the data values in dataList def max (dataList):        #returns the largest value def getRange (dataList) def mean (dataList) :     #returns the average of data values def median (dataList):    #returns the middle value of an ordered list #note: to sort the list first, may use the predefined sort function Then write a test1 function to test the above functions using...

  • Write four functions: (IN PYTHON 3) 1) bound(l) - given a list of integers l, compute...

    Write four functions: (IN PYTHON 3) 1) bound(l) - given a list of integers l, compute a tuple containing the minimum and maximum values (in that order) 2) span(l) - given a list of integers l, compute the difference between the minimum and maximum function. 3) mean(l) - given a list of integers l, compute the average. The return value will be a float. 4) stats(f, l) - given a function f and a list l, apply the function f...

  • Assignment: USING PYTHON Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called...

    Assignment: USING PYTHON Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called HelperClasses and create a class inside it called Helpers Inside Helpers, create 8 static methods as follows: 1.) Max, Min, Standard_Deviation, Mean a.) Each of these should take a list as a parameter and return the calculated value 2.) Bubble a.) This should take a list as a parameter and return the sorted list 3.) Median a.) This should take a list as a...

  • Test CASE: DATA1 = [1, 2, 3, 4, 5, 6] DATA2 = [i for i in range(100) if i % 3 == 0] assert(stats(span, DATA1) == 5) ass...

    Test CASE: DATA1 = [1, 2, 3, 4, 5, 6] DATA2 = [i for i in range(100) if i % 3 == 0] assert(stats(span, DATA1) == 5) assert(stats(mean, DATA1) == 3.5) assert(stats(bound, DATA2) == [0, 99]) Write four functions: 1) bound() - given a list of integers 1, compute a tuple containing the minimum and maximum values (in that order) 2) span() given a list of integers 1, compute the difference between the minimum and maximum function 3) mean() given...

  • A linked list of integers is built using the following struct: struct node {   int data;...

    A linked list of integers is built using the following struct: struct node {   int data;   struct node *next; }; Define a function named max that returns the maximum integer in a list. The function takes one arguments, a pointer to the head of the list. The function returns an integer, which is the maximum value. If the list is empty, return zero. NOTE: You know nothing about the values in the list. They could all be negative!

  • Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the...

    Create a CodeBlocks project "HW 9" Write the code to ask the user to enter the size of an array. Then create an integer array of that exact size. Ask the user to enter a maximum value and then write a loop to fill the array with random numbers with value in the range of 1 to the maximum value. For example, if the maximum value is 100, random numbers must have value 1 to 100 inclusive. Input size of...

  • Topics: list, file input/output (Python) You will write a program that allows the user to read...

    Topics: list, file input/output (Python) You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing student...

  • Assignment #2: List - Array Implementation Review pages 6-7 in "From Java to C++" notes. Due...

    Assignment #2: List - Array Implementation Review pages 6-7 in "From Java to C++" notes. Due Friday, February 9th, 2017 @ 11:59PM EST Directions Create a List object. Using the following definition (List.h file is also in the repository for your convenience) for a list, implement the member functions (methods) for the List class and store the implementation in a file called List.cpp. Use an array to implement the list. Write the client code (the main method and other non-class...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT