Question

A group of statisticians at a local college has asked you to create a set of...

A group of statisticians at a local college has asked you to create a set of functions that compute the median and mode of a set of numbers, as defined in Section 5.4. Define these functions in a module named stats.py. Also include a function named mean, which computes the average of a set of numbers. Each function should expect a list of numbers as an argument and return a single number. Each function should return 0 if the list is empty. Include a main function that tests the three statistical functions. Ask users to enter the list of numbers, and then choose which function to apply to those numbers. After the single number is returned from the correct function, display to the user the list of numbers, the function selected and the answer in a format that is easy to understand.

Please include flowchart

Homework Answers

Answer #1

Flowchart for problem:

Detailed Python Code:

from collections import Counter


def mean(lst):
    #n_num = [1, 2, 3, 4, 5] 
    if not lst:
        return 0
    n = len(lst) 
      
    get_sum = sum(lst) 
    mean = get_sum / n 
      
    return mean
    
    
def median(lst):
    if not lst:
        return 0
    n = len(lst) 
    lst.sort() 
    if n % 2 == 0: 
        median1 = lst[n//2] 
        median2 = lst[n//2 - 1] 
        median = (median1 + median2)/2
    else: 
        median = lst[n//2] 
    return median
    
    
def mode(lst):
    if not lst:
        return 0
    counter = Counter(lst)

    max_count = max(counter.values())

    mode = [k for k,v in counter.items() if v == max_count]
    return mode


if __name__ == '__main__':
    lst = [] 
    n = int(input("Enter number of elements : ")) 
      
    #print("Enter "+n+" elements seperated by pressing enter")
    for i in range(0, n): 
        ele = int(input()) 
      
        lst.append(ele)
        
        
    print(lst)
    
    while True:
        print("Press the number alongside to perform the required function:")
        print("1.Mean")
        print("2.Median")
        print("3.Mode")
        print("4.Exit")
        
        n=int(input())
        
        if(n==1):
            print("mean of numbers: "+str(mean(lst)))
        elif(n==2): 
            print("median of numbers: "+str(median(lst)))
        elif(n==3):
            print("mode of numbers: "+str(mode(lst)))
        elif(n==4):
            break
    
    
        
Know the answer?
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
Similar Questions
In C++ Employee Class Write a class named Employee (see definition below), create an array of...
In C++ Employee Class Write a class named Employee (see definition below), create an array of Employee objects, and process the array using three functions. In main create an array of 100 Employee objects using the default constructor. The program will repeatedly execute four menu items selected by the user, in main: 1) in a function, store in the array of Employee objects the user-entered data shown below (but program to allow an unknown number of objects to be stored,...
Function Example: Write a Python function that receives two integer arguments and writes out their sum...
Function Example: Write a Python function that receives two integer arguments and writes out their sum and their product. Assume no global variables. def writer(n1, n2): sum = n1 + n2 product = n1*n2 print("For the numbers", n1, "and", n2) print("the sum is", sum) print("and the product is", product) ... 1) Create a PYHW2 document that will contain your algorithms in flowchart and pseudocode form along with your screen shots of the running program. 2) Create the algorithm in both...
PYTHON Driver’s License The local driver’s license office has asked you to create an application that...
PYTHON Driver’s License The local driver’s license office has asked you to create an application that grades the written portion of the driver’s license. The paper has 20 multiple-choice questions. Here are the correct answers: A C A A D B C A C B A D C A D C B B D A Your program should store these correct answers in a list. The program should read the student’s answers for each of the 20 questions from a...
1. Write a function called compute_discount which takes a float as the cost and a Boolean...
1. Write a function called compute_discount which takes a float as the cost and a Boolean value to indicate membership. If the customer is a member, give him/her a 10% discount. If the customer is not a member, she/he will not receive a discount. Give all customers a 5% discount, since it is Cyber Tuesday. Return the discounted cost. Do not prompt the user for input or print within the compute_discount function. Call the function from within main() and pass...
C++ Goals  Build single linked lists using pointers  Learn how to manipulate linked lists...
C++ Goals  Build single linked lists using pointers  Learn how to manipulate linked lists In this lab, you will create simple single linked structures consisting of Node objects. Each node will have a pointer to the next node. You will use a head pointer to keep track of the first node in the linked list, and a tail pointer to keep track of the last node in the linked list. Set both head and tail to NULL when...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g,...
For a C program hangman game: Create the function int setup_game [int setup_game ( Game *g, char wordlist[][MAX_WORD_LENGTH], int numwords)] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) What int setup_game needs to do setup_game() does exactly what the name suggests. It sets up a new game of hangman. This means that it picks a random word from the supplied wordlist array and...
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
C++ ONLY -- PRACTICE ASSIGNMENT For our practice assignment we have to turn in 2 files...
C++ ONLY -- PRACTICE ASSIGNMENT For our practice assignment we have to turn in 2 files - Driver.cpp and StringQueue.h Driver.cpp is provided for us, but if there are any changes needed to be made to that file please let me know. Based on the instructions below, what should the code look like for StringQueue.h ? Create a class named StringQueue in a file named StringQueue.h. Create a QueueNode structure as a private member of the class. The node should...
IntList Lab Specifications You are required to come up with a single header file (IntList.h) that...
IntList Lab Specifications You are required to come up with a single header file (IntList.h) that declares and implements the IntNode class (just copy it exactly as it is below) as well as declares the IntList Class interface only. You are also required to come up with a separate implementation file (IntList.cpp) that implements the member functions of the IntList class. While developing your IntList class you must write your own test harness (within a file named main.cpp). Never implement...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). Details and Requirements Your class must allow for storage of rational numbers in a mixed number format. Remember that a mixed number consists of an integer part and a fraction part (like 3 1/2 – “three and one-half”). The Mixed class must allow for both positive and negative mixed number values. A...