1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Setler [38]
2 years ago
12

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.
Computers and Technology
1 answer:
Vanyuwa [196]2 years ago
8 0

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.

You might be interested in
Which view is most commonly used to make edits to a slide?
Varvara68 [4.7K]
The view that's most commonly used to make edits to a slide is the so-called normal view on PowerPoint. This view shows in a big plan on the main window of the PowerPoint the slide that is selected and therefore be edited. On a column on the left is the list of all slides on the presentation. On the bar on top are all tools for editing.
3 0
3 years ago
Read 2 more answers
Where does gateway antivirus scan for viruses
Serggg [28]
Gateway antivirus scan for viruses at the application level. Gateway antivirus allows for the checking of files for viruses by providing a web-based scanning service. It provides integrated antivirus security on the system which block the potential threat before reaching the network.
7 0
3 years ago
A ___________ is a computer processor which incorporates the functions of a computer's central processing unit (CPU) on a single
UNO [17]

Answer:

Microprocessor

Explanation:

A microprocessor is an integrated circuit (IC) which integrates core functions of a central processing unit. It is a programmable silicon chip, having several functions. It accepts binary data as input, processes this data according to the instructions stored in the memory and gives output after processing it. Microprocessor is comprised of an Arithmetic Logic Unit, Register Array, and a Control Unit. ALU performs arithmetical and logical operations on the data obtained from input device. Register array is comprised of registers like accumulator. They are temporary access memory locations to process data faster. The control unit controls the flow of data and instructions throughout the computer.

The instructions are stored sequentially in the memory. Microprocessor fetches those instructions, decodes and executes those instructions. This process ends when the microprocessor reaches Stop instruction. Then the  microprocessor sends the result in binary to the output port. Throughout this process the ALU performs arithmetic operations and registers act as temporary storage location for processing data.

Microprocessor is available at low price, its is portable, consumes less power, small in size, can work at very high speed, generate less heat, failure rate is less which makes it reliable and same chip can be utilized by various application which makes it versatile.

4 0
3 years ago
During the morning of a website launch for a new government sponsored healthcare portal, an unknown political rival, individual,
Softa [21]

The likely reason for the attack is an act of hacktivism as a way for the hacker to spread messages for their own agenda.

From the complete information given, during the morning of a website launch for a government-sponsored program, an unknown political rival had access to the server and the content showed human rights campaigns.

This is quite different from the original intent of the message to be sent. In this case, the reason for the attack is that the hacker wants to pass their own message to the people.

Read related link on:

brainly.com/question/25682883

4 0
2 years ago
14. Under the von Neumann architecture, a program and its data are both stored in memory. It is therefore possible for a program
irinina [24]

Answer:

Explanation:

This sort of scenario can be very problematic for a programmer. When writing code, pieces of code are designed to connect with each other and depend on specific information provided by other blocks of code. If one of these blocks of code or programs modifies itself and changes even the smallest value, then the code will output a completely different value or instruction that was intended by the programmer when initially creating the code. This tiny change can cause the entire code/program to fail and give an error that would be very difficult to fix.

6 0
3 years ago
Other questions:
  • What will happen if more than 2 devices attempt to access the internet ?
    15·1 answer
  • Help! live preview in brackets is not working
    8·1 answer
  • What additive keeps engines clean by preventing contaminates and deposits from collecting on surfaces? a. Friction modifiers b.
    10·2 answers
  • Telepresence provides the opportunity for people to work from home and attend virtually. True False
    5·2 answers
  • Matthew is running a study on the effects of room temperature on performance on an algebra test. One group takes the test in a r
    5·1 answer
  • Name the contributions of Steve Jobs and Bill Gates, with respect to technology.
    5·1 answer
  • Which of the following is a windows that allows you to temporarily store text
    15·1 answer
  • ) A stub network has ______. (Points : 2) one backup route
    10·1 answer
  • PLS ANSWER ASAP I WILL GIVE BRAINLIEST
    11·1 answer
  • Help please and thank you :)
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!