I am studying at uni and am re-sitting my python module. Which is different to the first year and im struggling a fair bit.
Ok im not looking for anyone to do the work for me but with the second and third section i have no idea where to start. The first section i have done the following. Anyway i will post and if you need more or less information just let me know. To begin with i will put up the first assignment and what i have done.
Assignment 1
Q1
Create new Python files/modules called main.py, publication.py, book.py and
disc.py. The modules will provide some simple facilities for representing different types of
publications.
In the modules above, create three new classes: Publication, Book and Disc in appropriate
files. Book and Disc should both be subclasses of Publication. Publication should be a
subclass of Python’s special class object (remember, if your class doesn’t inherit from any other
class, then you should make it inherit from object). The Publication class should store the title,
publication date and publicationID of a publication. A default ID of xxxx should be given to all
publications when created.
Q2
Next, the Book class should also have a private pagecount attribute of type integer and Disc
should have a private playingtime (in minutes) attribute of type integer. Each of these three
classes should have a public displayInfo() method that prints the details of the object to the
terminal.
Q3
Its a good idea to test your classes to make sure they work. To save you some time, a test function has
been provided. You can copy and paste the code from this document into the main.py module
(which, don't forget, imports the publication, book and disc classes).
def test():
book1=Book('Lord of the Kings','Science Fantasy',987)
book2=Book('Love Never Dies','Romance',176)
book3=Book('Ten to Midnight','Crime Thriller',235)
disc1=Disc('Hello Dolly','Comedy',115)
disc2=Disc('Lord of the Rings','Science Fantasy',542)
disc3=Disc('Needles and Pins','Medical Reference',120)
print '\nTesting...\n'
book1.displayInfo()
book2.displayInfo()
book3.displayInfo()
disc1.displayInfo()
disc2.displayInfo()
disc3.displayInfo()
if __name__=='__main__':
test()
print'\nHave a nice day'
Save the screen output of the test function above to test your program and prove that it works.
Q4
Add a new method called updateID() to the publication class. This should prompt the user for input
and then assign the value entered to the publicationID private attribute. publicationID
should be of type string.
Q5
Modify the test() method so that it uses a list of Book and Disc objects. Loop through the list
and print each object’s information to the screen using the displayInfo() method.
You'll need to figure out where to initialise your list. It could look something like:
publist = [Book('Lord of the Rings','Science Fantasy' ),
Book('Love never dies','Romance'),
Book('Use of Weapons','Science Fiction'),
Disc('Hello Dolly','Comedy'),
Disc('Lord of the Rings','Science Fantasy')]
Q6
Briefly describe the following concepts: classes, inheritance, superclasses, subclasses
(I have done this question, just thought id leave it on here for reference)
The Code so far
#main py
def test():
book1=Book('Lord of the Kings','Science Fantasy',987)
book2=Book('Love Never Dies','Romance',176)
book3=Book('Ten to Midnight','Crime Thriller',235)
disc1=Disc('Hello Dolly','Comedy',115)
disc2=Disc('Lord of the Rings','Science Fantasy',542)
disc3=Disc('Needles and Pins','Medical Reference',120)
print '\nTesting...\n'
book1.displayInfo()
book2.displayInfo()
book3.displayInfo()
disc1.displayInfo()
disc2.displayInfo()
disc3.displayInfo()
if __name__=='__main__':
test()
print'\nHave a nice day'
# Book Class Definition
class Book:
def__init__(self,title,genre,number):
self.title=title
self.genre=genre
self.number=number
def __init__(self,title,genre,number):
Publication.__init__(self,title,genre)
return
# Disk Class Definition
class Disk:
def__init__(self,title,genre,number):
self.title=title
sefl.genre=genre
self.number=number
def __init__(self,title,genre,number):
Publication.__init__(self,title,genre)
return
# Publication class definition
class(object)
class publication(object):
def__init__(self,title,genre)
self.title=title
self.genre=genre
self.defaultID=xxxx
return
Right any help will be greatly appreciated.
This post has been edited by langers_2004: 06 June 2011 - 05:16 AM

New Topic/Question
Reply



MultiQuote





|