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
Enzymes_____________.
lord [1]

Answer:

b. speed up chemical reactions.

Explanation:

brainly plz

4 0
3 years ago
What is another name for maize?
Oliga [24]
Hunted house? maize is what I call the haunted houses from knots spray farm or universal studios
5 0
3 years ago
Consider the following scenario. The Current State of One Particular ArrayList The capacity of a particular ArrayList is five (5
pshichka [43]

Answer:

The ArrayList initial functionality is 5, there were 4 components.

Then, add 25 more elements by using add()calling 25 times So total number of elements after the completed operation would be 4 + 25= 29.

5th component will be introduced without calling ensureCapacity(); while adding 6th element-> ensureCapacity(2* 5+ 1) it will call, making the capacity 11.

So ArrayList's capacity will be 11.

Next 7th to 11th components will also be added automatically once the 12th element is added, it will name ensureCapacity(2* 11+ 1) and make the capacity 23.

While adding 24th dimension, ensureCapacity(2* 23+ 1) will be called again and this will make the capacity 47.

There will therefore be 3 (three) calls to ensure the feature Ability).  

Elements of Rest 25th to 29th will be added seamlessly as ability becomes 47.

3 0
3 years ago
21. Dice Game Write a program that plays a simple dice game between the computer and the user. When the program runs, a loop sho
Brrunno [24]

Answer:

See Explanation Below

Explanation:

// Program is written in C++ programming language

//.. Comments are used for explanatory purposes

// Program starts here

#include<iostream>

#include <stdlib.h>

#include <time.h>

using namespace std;

int main()

{

int computerWins = 0, computerPlay = 0;

int userWins = 0, userPlay = 0;

int tiedGames = 0;

// Computer Play

for (int play = 0; play< 10; play++) {

   computerPlay = rolls();

   userPlay = rolls();  

   // Check who wins

//Clear Screen

System("CLS")

   if (computerPlay == userPlay) {

       tiedGames++;

cout<<"Ties........" + tiedGames;    }

else {

       if (computerPlay> userPlay) {

           computerWins++;

cout<<"Computer...."<< computerWins;

       } else {

           userWins++;

cout<<"User........"<< userWins;

      }

  }

}

return 0;

}

int rolls() {

srand((unsigned)time(0));

return rand() % 6 + 1;

}

5 0
3 years ago
What tools you need to use to migrate Metadata to Two Different Production Orgs?
sammy [17]

Answer:D.

Explanation:I just did this and d is right

8 0
3 years ago
Other questions:
  • What effect can camera tilt create? Do you think this is effective? Why or why not?
    13·1 answer
  • Difference between volatile and non volatile memory
    14·2 answers
  • Kiera is building a new computer and wants to make sure she has an adequate power supply for all the new equipment she is purcha
    15·2 answers
  • This isn't a homework question but rather a technological problem. I connected my device to the motherboard but it will not dete
    5·2 answers
  • The browser on which you are viewing web pages is called the
    13·1 answer
  • Describe how a web browser and web server work together to send a web page to a user
    8·1 answer
  • Can you guys give some samples of STEM-related studies?​
    7·2 answers
  • What is the function of a bread crumb trial in a website
    11·1 answer
  • Convertbinary(111100)to decimal​​​​
    13·2 answers
  • What are the different types of monitors?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!