Measures of Central Tendency

Easy
15
80.3% Acceptance

In this lab, you are tasked with implementing a Python function named central_tendency. This function should take a list of numerical data as input and calculate the mean, median, and mode of the data. The function should then return these values in a dictionary and also display them.

Required Function Output

  • The function should return a dictionary with keys as 'mean', 'median', and 'mode', and their respective calculated values.
  • Additionally, the function should print these values.
  • Make sure to round the output generated to two decimal places. If you're output contains more than two decimal places the test cases will fail

Examples

  1. Input: [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
    Output: {'mean': 55, 'median': 55, 'mode': 10}

  2. Input: [1, 2, 2, 3, 4]
    Output: {'mean': 2.4, 'median': 2, 'mode': 2}

Formulas

  • Mean: The average of all numbers. Calculated as the sum of all numbers divided by the count of numbers.

    mean image

  • Median: The middle value in the sorted list of numbers. If the list has an even number of elements, the median is the average of the two middle numbers.

    median image

  • Mode: The number that appears most frequently in the list. If all numbers appear with the same frequency, the set is considered to have no mode.

Ensure your implementation handles various types of input lists accurately and efficiently. Good luck!

TIP: You can use the statistics module to write the function easily