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
Elden [556K]
3 years ago
7

Implement a container class Stat that stores a sequence of numbers and provides statistical information about the numbers. It su

pports an overloaded constructor that initializes the container either by supplying a list or by giving no arguments (which creates an empty sequence). The class also includes the methods necessary to provide the following behaviors:
>>> s = Stat()
>>> s.add(2.5)
>>> s.add(4.7)
>>> s.add(78.2)
>>> s
Stat([2.5, 4.7, 78.2])
>>> len(s)
3
>>> s.min()
2.5
>>> s.max()
78.2
>>> s.sum()
85.4
>>> s.mean()
28.46666666666667
>>> s.clear()
>>> s
Stat([])
If a Stat is empty, several (but not all) methods raise errors. Note that you won’t literally see "…". You will instead see more information on the error.
>>> s = Stat()
>>>
>>> len(s)
0
>>> s.min()
Traceback (most recent call last):
...
EmptyStatError: empty Stat does not have a min
>>> s.max()
Traceback (most recent call last):
...
hw3.EmptyStatError: empty Stat does not have a max
>>> s.mean()
Traceback (most recent call last):
...
hw3.EmptyStatError: empty Stat does not have a mean
>>> s.sum()
0
Computers and Technology
1 answer:
olga2289 [7]3 years ago
6 0

Answer:

See explaination

Explanation:

Definition of Class 1:

class Stat:

def __init__(self, li):

self.li = li

def add(self, value):

self.li.append(value)

def __len__(self):

return len(self.li)

def min(self):

try:

return min(self.li)

except:

return "EmptyStatError: empty Stat does not have a min"

def max(self):

try:

return max(self.li)

except:

return "EmptyStatError: empty Stat does not have a max"

def sum(self):

return sum(self.li)

def mean(self):

try:

return float(sum(self.li))/float(len(self.li))

except:

return "EmptyStatError: empty Stat does not have a mean"

def __getitem__(self):

return self.li

def clear(self):

del self.li[:]

Definition of Class 2:

class intlist:

def __init__(self, li):

self.li = li

def append(self, value):

if type(value) == int:

self.li.append(value)

else:

print "NotIntError: Input is not an Integer."

def insert(self, index,value):

if type(value) == int:

self.li.insert(index, value)

else:

print "NotIntError: Input is not an Integer."

def extend(self, value):

i = 0

for temp in value:

if type(temp) == int:

i = i

else:

i = i+1

if i==0:

self.li.extend(value)

else:

print "NotIntError: Input is not an Integer."

def __setitem__(self, index, value):

self.insert(index, value)

def __getitem__(self, index):

return self.li[index]

def odds(self):

lis = []

for temp in self.li:

if temp%2 == 1:

lis.append(temp)

return lis

def evens(self):

lis = []

for temp in self.li:

if temp%2 == 0:

lis.append(temp)

return lis

Class 1 call:

s = Stat([])

s.add(2.5)

s.add(4.7)

s.add(78.2)

print len(s)

print s.min()

print s.max()

print s.sum()

print s.mean()

print s.li

s.clear()

print s.li

print len(s)

print s.min()

print s.max()

print s.mean()

print s.sum()

Class 2 call:

intl = intlist([])

print intl.li

intl = intlist([1,2,3])

print intl.li

intl.append(5)

print intl.li

intl.insert(1,99)

print intl.li

intl.extend([22,44,66])

print intl.li

print intl.odds()

print intl.evens()

print intl.li

intl[2] = -12

print intl[4]

You might be interested in
You have just taken over management of a server on which the previous server administrator has set up several server components,
Arisa [49]

Answer:

d. Ensure file caching and flushing are enabled for all disk drives.

Explanation:

When the disk reading and writing is delayed and the server performance is also slow after taking over management of a server.Previously the server has several server components.So to increase the performance we should ensure caching of the file and make sure that the flushing is enabled for all disk drives.Hence the answer to this question is option d.

8 0
3 years ago
Which wireless security methods uses a common shared key configured on the wireless access point and all wireless clients?
Korolek [52]

Answer:

WEP, WPA Personal, and WPA2 personal, these are the wireless security method which are used common shared key configured on the wireless access point and wireless clients. WEP is the wired equivalent privacy and WPA stands for wifi protected access.

These are the wireless security protocols, which basically provide the wireless security to the system. Wireless network are transmitted within the range for every direction. WPA modern application used the pre shared key system and this system are developed for link the device to the access point easily.

4 0
4 years ago
Write a for loop that sets each array element in bonusScores to the sum of itself and the next element, except for the last elem
Nat2105 [25]

Answer:

The program to this question can be given as:

Program:

#include<stdio.h>  //header file.

int main()

 //main function

{

   int SCORES_SIZE = 4;  //define variables.

   int bonusScores[]={10,20,30,40};  //define array.

   int i;

   printf("Values:");

 //message

   for (i = 0; i < SCORES_SIZE; ++i)  //loop for print values.

   {

       printf("%d ", bonusScores[i]);

   }

void CombineScores(int numberScore, int userScore) //function

{

   for (i = 0; i < SCORES_SIZE; i++)

  //loop for convert values

   {

       if (( bonusScores[i] <= bonusScores[i +1] ) || (bonusScores[i] < bonusScores [i+1]))  //check array elements

       {

           bonusScores[i] = (bonusScores [i] + bonusScores[i+1]);

 //add values

       }

       else

       {

           bonusScores[i] = bonusScores[i];

       }

   }

   printf("\nReturn values:");  //message

 for (i = 0; i < SCORES_SIZE; i++)

{

printf("%d",bonusScores[i]);

}

}

CombineScores(0,0); //calling

return 0;

}  

Output:

Values:10 20 30 40  

Return values:30 50 70 40  

Explanation:

In the above c++ programming code firstly we define the header file. Then we define the main function in this function we define variable that name is given in the question that is SCORES_SIZE, i. Variable i is used in the loop for a print array. Then we define and initialize an array. The array name is and elements are define in the question that is bonusScores[]={10,20,30,40}. Then we use the loop for print array elements.Then we define function that is CombineScores() in this we pass two parameter. Then we use the second time in this loop we check array elements and add the elements that are given in the question. In this function we print values and at the end we call function.

3 0
3 years ago
What types of data might you insert into an Excel workbook to be used in an annual financial statement?
Alex Ar [27]
The correct answer for this question is this one: "numerical and financial data." <span>The types of data that you might insert into an Excel workbook to be used in an annual financial statement includes numerical data and financial data."</span>
Hope this helps answer your question and have a nice day ahead.
4 0
3 years ago
What made the master so angry with his servant?​
sergeinik [125]

Answer:

what book?

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • 6. An art museum owns a large volume of works of art. Each work of art is described by an item code (identifier), title, type, a
    6·1 answer
  • Ryan is looking at investment opportunities as a cloud service provider. He wants to invest in a deployment-based cloud model th
    11·2 answers
  • Javascript or java? which one is better?
    13·2 answers
  • Initially, later, and finally are examples of what kind of words
    9·1 answer
  • Search engines that search other search engines are called
    12·2 answers
  • Fill in the blank.
    7·1 answer
  • For Windows 9x and Windows NT operating systems, which authentication protocol should be used that protects the authentication p
    11·1 answer
  • Should the federal government have bug bounty programs? Why or why not?
    9·2 answers
  • Create a Python program that: Allows the user to enter a person's first name and last name. The user should be able to enter as
    12·1 answer
  • Free coins who is octane and dont say u dont know because i will do the same to u
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!