Question

In: Statistics and Probability

PYTHON IS3073 1. A group of statisticians at a local college has asked you to create...

PYTHON IS3073

1. 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 with a given list.

7. Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order.

8. A file concordance tracks the unique words in a file and their frequencies. Write a program that displays a concordance for a file. The program should output the unique words and their frequencies in alphabetical order. Variations are to track sequences of two words and their frequencies, or n words and their frequencies.

Solutions

Expert Solution

1) The Python code to compute mean, median and mode of a set of data is given below.

Input the data as an array to each functions.

def mean(data):
    total = 0
    num_elements =len(data)
    if(num_elements  == 0):
        return(0)
    for item in data:
        total = total + item
    mu = total / (num_elements) # alternately mean = (total / len(data))
    return (mu)

def median(data):
    num_elements =len(data)
    if(num_elements  == 0):
        return(0)
    data.sort()
    # determine even or odd
    even = True
    if len(data)%2 == 1:
        even = False
    if even:
        slice_start = (len(data)//2) - 1
        slice_end   = (len(data)//2) + 1
        me      = sum(data[slice_start:slice_end]) / 2
    else:
        me      = data[len(data)//2]
    return (me)

def mode(data):
    num_elements =len(data)
    if(num_elements  == 0):
        return(0)
    hits = []
    for item in data:
        tally = data.count(item)
        values = (tally, item)
    # Only add one entry for each number in the set
        if values not in hits:
           hits.append(values)
    hits.sort(reverse=True)
    if hits[0][0]>hits[1][0]:
        return(hits[0][1])
    else:
        print("\nThere is not a mode")
        return(0)

if __name__ == "__main__":
    data = [2,4,6,5,7,8]
    print("\nThe mean is:", mean(data))
    print("\nThe median is:", median(data))
    print("\nThe mode is:", mode(data))

The output is:

The mean is: 5.333333333333333

The median is: 5.5

There is not a mode

The mode is: 0

We are required to answer only one question. Post the remaining questions as another post.


Related Solutions

You are volunteering for a local children's softball league. They asked you to create an app...
You are volunteering for a local children's softball league. They asked you to create an app or a Web application to help in their operations. You decide to create a database. The league consists of several teams. Players are assigned to teams at the start of the season. It also collects parents' contact information, and charges season and optional equipment rental fees. League volunteers include officials, referees, coaches, and first aid attendants. Parents also volunteer to help at individual practices...
A group of 100 college students and 100 college graduates was asked to reply to the...
A group of 100 college students and 100 college graduates was asked to reply to the question, "In general, do you enjoy reading a college textbook?" The following are the frequency counts for their responses on the 3-option item. Usually Sometimes Never Students 30 25 45 Graduates 50 20 30 The critical value that you would use for an alpha level of .10 in the problem comparing college students' and graduates' enjoyment of reading textbooks is?
You have been asked to serve as a consultant for a local support group for cancer...
You have been asked to serve as a consultant for a local support group for cancer patients. They would like you to do the following: 1) provide a presentation on health literacy; 2) draft a handout on how to find quality information related to cancer care, study findings, and treatment implications based upon study findings. As you prepare for both of these charges, what would be some key points and resources that you would want to share with the group?
Your local community college is opening a new campus in a different city and has asked...
Your local community college is opening a new campus in a different city and has asked your software firm to create a student roster program. You first have to develop a class that represents the roster of students who are currently studying in this local community college. What components and attributes will need to be included in the Student class? Why?  Please include a Python code sample.
You have been asked to create a python program that will ask the user how many...
You have been asked to create a python program that will ask the user how many tickets the user would like to purchase for graduation. The user will then choose the number of tickets needed and the program will list the cost of the tickets, a service fee, tax, and the total of the purchase. Specifications: The program should only accept whole numbers when receiving input for the number of tickets needed. No calculations should be performed if input is...
You have been asked by your local elementary school principal to address a group of parents...
You have been asked by your local elementary school principal to address a group of parents about the problem of obesity. Among the topics you have been asked to talk about are good nutrition, exercise, and lifestyle changes. Since all your parents are adult, list five principles of adult learning and describe how you would incorporate them into your teaching plan?
You have been asked by your local elementary school principal to address a group of parents...
You have been asked by your local elementary school principal to address a group of parents about the problem of obesity. Among the topics you have been asked to talk about are good nutrition, exercise, and lifestyle changes. Since all of your parents are adults, list five principles of adult learning, and describe how you would incorporate them into your teaching plan.
For Python: In this assignment you are asked to write a Python program to determine the...
For Python: In this assignment you are asked to write a Python program to determine the Academic Standing of a studentbased on their CGPA. The program should do the following: Prompt the user to enter his name. Prompt the user to enter his major. Prompt the user to enter grades for 3 subjects (A, B, C, D, F). Calculate the CGPA of the student. To calculate CGPA use the formula: CGPA = (quality points * credit hours) / credit hours...
Using python. 1. How to create a dictionary that has an integer as a key and...
Using python. 1. How to create a dictionary that has an integer as a key and a byte as a value? the dictionary keys must contain integers from 0 to 255. It should be similar to UTF-8. When we enter an integer, it should return 1 byte. 2. Create a function when a user gives 1 byte, it should return the key from the previous dictionary.
You are working for a local accountant during tax season and the accountant has asked you...
You are working for a local accountant during tax season and the accountant has asked you to prepare the appropriate tax form for Ace Company. Ace Company is a newly formed handyman business owned by Mr. and Mrs. Becker. Mrs. Becker just enrolled in her first bookkeeping class and created the spreadsheet you were given (attached file located above).   As you can see Mrs. Becker left you a note about not paying any taxes this year.   Update Mrs. Becker’s spreadsheet for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT