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]
4 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]4 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
The page-replacement policy means that pages are not placed to make more space. A. True B. False
BabaBlast [244]

Answer:

B. False

Explanation:

A page-replacement policy can be defined as a set of algorithm that instructs the operating systems on what memory page is to be swapped, paged out or written to disk in order to allocate more memory as they're required by various active processes during virtual memory management.

Some of the algorithms or techniques used by the operating system for page-replacement policy are;

1. Last In First Out (LIFO).

2. First In First Out (FIFO).

3. Least Recently Used (LRU).

4. Least Frequently Used (LFU).

5. Optimal (OPT or MIN).

Hence, the page-replacement policy means that pages are placed to make more space and to minimize the total number of page that would be missing.

7 0
3 years ago
The compiler decides which version of a polymorphic method to call at compile time
astra-53 [7]

Answer:

T

Explanation:

Hope it's help.you.

plz Mark me as brinliest

Thank you

8 0
3 years ago
Middleware for cloud database applications is commonly written as ____—short sections of code written in a programming or script
Ostrovityanka [42]
<span>Middleware for cloud database applications is commonly written as scripts—short sections of code written in a programming or scripting language that are executed by another program. A script language is used for server side scripting language that can change a specific data on the server. Examples of these are PHP, JSP, Perl, Python, etc.</span>
5 0
4 years ago
Describe how sharing and collaborating a spreadsheet can help the author of the spreadsheet.
Reika [66]
It can help ensure that everything is correct. Having an extra set of eyes can never hurt :)
3 0
3 years ago
List of steps to apply bold and italic formatting to a word​
ch4aika [34]
To make text bold, select and highlight the text first. Then hold down Ctrl (the control key) on the keyboard and press B on the keyboard. To make text italic, select and highlight the text first. Then hold down Ctrl (the control key) on the keyboard and then press the I on the keyboard
5 0
4 years ago
Read 2 more answers
Other questions:
  • You just realized the turn signal on your vehicle is broken,
    15·1 answer
  • When creating databases, the different pieces of information are input into _______.
    7·1 answer
  • Which option describes wearable technology?
    5·2 answers
  • What are programming paradigms?​
    9·1 answer
  • In the MARS Marketing Management Simulation, the results of your marketing mix decisions:
    9·1 answer
  • Who are the best candidates for members of skills USA?
    8·1 answer
  • Data management technology consists of the: Group of answer choices physical hardware and media used by an organization for stor
    13·1 answer
  • If x=3.123, then int(x) will give ?
    5·1 answer
  • 1 cup coffee cream = ____ tbsp butter plus ____ c milk
    11·1 answer
  • "To speed up magnetic hard drive performance , ___________ is often used. "
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!