Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Python 3+ 1.) Implement a container class Stat that stores a sequence of numbers and provides statistical information about the numbers. It supports an

Using Python 3+

1.) Implement a container class Stat that stores a sequence of numbers and provides statistical information about the numbers. It supports 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:

The following Doc Test must pass with 0 failed results for the program to be 100% complete:

>>> 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([])

#what happens if the stat is empty? #most methods give errors

#If a Stat is empty, several (but not all) methods raise errors. Note that you wont literally see . You will #instead see more information on the error.

>>> s = Stat() >>> >>> len(s) 0 >>> s.min() #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... EmptyStatError: empty Stat does not have a min >>> s.max() #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... EmptyStatError: empty Stat does not have a max >>> s.mean() #doctest: +IGNORE_EXCEPTION_DETAIL Traceback (most recent call last): ... EmptyStatError: empty Stat does not have a mean >>> s.sum() 0

#make sure empty Stats are distinct #(using None for default argument in init)

>>> s = Stat() >>> s.add(33) >>> t = Stat() >>> t # make sure using None as default in init Stat([])

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions