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.

Answers

Answer 1
Answer:

Answer:

from functools import reduce

def mean(mylist):

   score = reduce(lambda x,y: x + y, mylist)/ len(mylist)

   return score

def median(mylist):

   sorted(mylist)

   list_len = len(mylist) % 2

   i = round(len(mylist)/2)

   x = len(mylist)//2

   if list_len == 0:

       median = (mylist[x] + mylist[x+1]) / 2  

   else:

       median = mylist[i]

   return median

def mode(mylist):

   unique = set(mylist)

   unique = list(unique)

   collector = [mylist.count(key) for key in unique]

   maxi = max(collector)

   loc = collector.index(maxi)

   return unique[loc]

def main():

   scores = input( 'Enter list of numbers: ').split(",")

   scores = [int(score) for score in scores]

   

   operation = input('Enter operation: ')

   operator = ['mean', 'median', 'mode']

   

   for x in iter(list, 0):

       if operation in operator:

           break

       print("Invalid operation: ")

       operation = input('Enter operation')

   

   index_loc = operator.index(operation)

   

   if index_loc == 0:

       return mean(scores)

   elif index_loc == 1:

       return median(scores)

       #return np.median(scores)  can be used of the defined function

   elif index_loc == 2:

       #return stats.mode(scores)[0]  can be used of the defined function

       return mode(scores)

print( main( ) )

Explanation:

The main python function calls conditionally three statistical functions namely mean, median and mode. It prompts for user input for a list of integer numbers and a function name name to return the corresponding result.


Related Questions

The agency responsible for maintaining a database of all operational continuity facilities is:
(multiple choice)Select the items that describe possible problems with being unemployed and not earning income. People cannot afford to buy food. People cannot support their families.People cannot afford medical treatment. People cannot afford housing.
Which of the following is NOT one of Facebook s main features? Private messages Posts from friends Status updates Web searching
A benefit of flashcards is that they area. Portable c. Very large b. Contains lots of information d. Ask many questions on one card
ICS facilitates the ability to communicate by using:a. ICS-specific codes. b. Acronymds. c. Common terminology. d. N,coIMS lexicon.

What are 3 machines or divices that depend on gravity to work

Answers

There are very many machines that depend on gravity to work. Apart from the ones mentioned here earlier, the other three machines and devices include, gravity powered solar tracker, water powered cable trains, human powered Ferris wheel and gravity powered lights.

Gravity-Powered Solar Tracker - Using gravitational power and water, this solar powered tracker ensures a solar panel follows the sun throughout the day, producing clean drinking water

Water powered cable trains - They are energy - efficient modes of transport out there. Majority of these machines are powered by water and gravity.


satelite, weight scale, and shower sar, running shoes, bowling ball. lawn mower, chair, frying pan. table cloth, playground swing, watering can.

Name the functional arms of MSDE.

Answers

Answer:

It is aided in these initiatives by its functional arms – National Skill Development Agency (NSDA), National Skill Development Corporation (NSDC), National Skill Development Fund (NSDF) and 33 Sector Skill Councils (SSCs) as well as 187 training partners registered with NSDC.

Lenders always accept applications for credit

Answers

The correct answer to the question that is being stated above is FALSE.

The statement is false because lenders do not always accept applications for credit. Lenders always consider credit history of the applicant. If the applicant has a good credit history background, then he qualifies.

What may happen if there is too much harmony in a design?A
It can appear cluttered.

B
It can seem boring.

C
It can be hard to read.

D
It can be too easy to copy.

Answers

Answer:

B It can seem boring.

Explanation:

The recurrence of visual effects results in inconstancy, beat, and drive. Though, too abundant replication can originate dullness and boredom. Also, this is not decent for you positively. You are positively going to miss the spectators. And too abundant harmony in strategy as well in an alike way origins boredom, or it can appear boring. And henceforth, the precise choice here is B it can seem boring.

2 9 10 Ready Sheetl Match the following columns: Column A Worksheet o Workbook o Cell Active cell o Columns Rows E MAA Column B o horizontal divisions of a worksheet. o a small rectangular area ● Vertical division of worksheet Fill in the blanks with suitable words: o has maximum 1048576 rows and 18278 (A to ZZZ) columns May contain several worksheets o Selected cell in the worksheet e. f. 5 identi Columns are iden g. The int rectan Write do Comm Save, Cut, Inse For Zo N 6 A 2​

Answers

Match:

  • A - Workbook
  • B - Rows
  • C - Cell
  • D - Active cell
  • E - Columns
  • F - Worksheet

Fill in the blanks:

A workbook has maximum 1048576 rows and 18278 (A to ZZZ) columns.

A worksheet may contain several worksheets.

The selected cell in the worksheet is the active cell.

Columns are identified by letters (A, B, C, etc.).

The intersection of a row and column forms a cell.

Commands:

  • Comment
  • Save
  • Cut
  • Insert
  • Format

For Zoom, use Ctrl + Mouse Scroll.

Sean is a lineman who is always on call to travel whenever there is a natural disaster. He has recently been called to help repair downed power lines for those who have been affected by a hurricane. What Energy cluster pathway does Sean work in? Environmental Resources Energy and Power Technology Telecommunications Plant Systems

Answers

Answer:

Energy and Power Technology

Explanation:

Energy and Power Technology is a field in engineering that typically deals with generation, transmission and distribution of electric energy to the end users. This energy are usually transmitted and distributed through the use of overhead cables running from the point of generation to the location of the end users.

Natural disasters such as hurricane, tornadoes, earthquake, etc., are capable of destroying the power lines (cables) as they are usually hung on poles.

In this scenario, Sean is a lineman who is always on call to travel whenever there is a natural disaster. He has recently been called to help repair downed power lines for those who have been affected by a hurricane. Therefore, the Energy cluster pathway that Sean works in is Energy and Power Technology.