Question: Consider the following classes, FileExtensionError and AudioFile: In [7]: class FileExtensionError( Exception ): pass class AudioFile: A class for representing a generic audio file

Consider the following classes, FileExtensionError and AudioFile:

In [7]:

 
class FileExtensionError( Exception ):
 pass
 
class AudioFile:
 """
 A class for representing a generic audio file
 """
 def __init__( self, filepath ):
 if not filepath.endswith( self.extension ):
 raise FileExtensionError( "File {filepath} does not have the expected extension ({self.extension})" )
 self.filepath = filepath

Now define the following classes as subclasses of AudioFile:

WAV_File

AIFF_File

FLAC_File

OGG_File

MP3_File

where each subclass defines a class variable named extension that specifies the expected file extension for the particular audio file that subclass represents and a play( self ) method that pretends to play the audio content in the specified file path. Just like the textbook example, all you need to do is to print out a message that informs the user that the particular file is being played.

WRITE YOUR CODE BELOW

In [6]:

 
#
#
#
# YOUR CODE GOES HERE
#
#
#

Create different numbers of files from each of the above file formats, and add these to a list. You can use the random module to randomize how many of each audio types you wish to create.

Run a for-loop to play each audio file

WRITE YOUR CODE BELOW

In [6]:

 
#
#
#
# YOUR CODE GOES HERE
#
#
#

QUESTION 2

Following the specifications in Question 1 above, create three (3) new audio file format classes with the following names:

WMA_File

PCM_File

AAC_File

WRITE YOUR CODE BELOW

In [6]:

 
#
#
#
# YOUR CODE GOES HERE
#
#
#

Create different numbers of files from each of the above file formats, and add these to a list. You can use the random module to randomize how many of each audio types you wish to create.

Run a for-loop to play each audio file

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!