Welcome to Dream.In.Code
Become an Expert!

Join 149,593 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,849 people online right now. Registration is fast and FREE... Join Now!




Never programmed b4. please help!

 
Reply to this topicStart new topic

Never programmed b4. please help!, small Database

mjsinpl
14 Oct, 2007 - 05:42 AM
Post #1

New D.I.C Head
*

Joined: 14 Oct, 2007
Posts: 3


My Contributions
Please help! I have just transferred into a new uni and i have never done any programming before. i have been asked to complete an assignment which i assume is simple however seeing that i have never done any b4 i really dont understand what is going on here.. i will attach scans of the assignment.. any help would be greatly appreciated. Any at all!! biggrin.gif


Attached thumbnail(s)
Attached Image Attached Image
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Never Programmed B4. Please Help!
14 Oct, 2007 - 06:22 AM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
no one here is going to do your assignment for you. You will have to ask questions or make an attempt, and we will help with errors and problems you have.

User is offlineProfile CardPM
+Quote Post

mjsinpl
RE: Never Programmed B4. Please Help!
14 Oct, 2007 - 06:28 AM
Post #3

New D.I.C Head
*

Joined: 14 Oct, 2007
Posts: 3


My Contributions
QUOTE(William_Wilson @ 14 Oct, 2007 - 07:22 AM) *

no one here is going to do your assignment for you. You will have to ask questions or make an attempt, and we will help with errors and problems you have.



No I wasn't hoping that someone would do it for me at all. Not what i had in mind trust me. I was simply hoping that someone could help me understand some of the terms used, maybe give push in a general direction so i can try start it. At the moment it feels as though i am looking at Chinese. blink.gif

If someone you could maybe show me how to successfully create classes. or explain what the special object class.
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Never Programmed B4. Please Help!
14 Oct, 2007 - 06:40 AM
Post #4

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,101



Thanked: 25 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
QUOTE

If someone you could maybe show me how to successfully create classes. or explain what the special object class.

that was a much better question!

Try the tutorials here: http://www.python.org/doc/Intros.html
They start basic and descriptive and move up into more complex things smile.gif
User is offlineProfile CardPM
+Quote Post

mjsinpl
RE: Never Programmed B4. Please Help!
14 Oct, 2007 - 09:27 AM
Post #5

New D.I.C Head
*

Joined: 14 Oct, 2007
Posts: 3


My Contributions
Alrighty o! i had a look at your tutorial and have created the classes the way that are supposed to look. so what i need help with is how to add an attribute "displayinfo" which will display the details of my three objects.

#!/usr/bin/python


# your 3 Classes are: Publication, Book and Disc
# 1st Class is Publication with Special Class (object)





class Publication:
def __init__ (self,pubtitle,pubgenre):
self.title = pubtitle
self.genre = pubgenre
self.pubID = 'xxxx'
return



class Book(Publication):
def __init__ (self,pubtitle,pubgenre,bookpages):
Publication.__init__(self,pubtitle,pubgenre)
return






class Disc(Publication):
def __init__ (self,pubtitle,pubgenre,bookpages):
Publication.__init__(self,pubtitle,pubgenre)
return






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'



results are!!!:

Testing...

Traceback (most recent call last):
File "C:/Documents and Settings/Mike/Desktop/Python work/experiment.pyw", line 62, in <module>
test()
File "C:/Documents and Settings/Mike/Desktop/Python work/experiment.pyw", line 52, in test
book1.displayInfo()
AttributeError: Book instance has no attribute 'displayInfo'
>>>

This post has been edited by mjsinpl: 14 Oct, 2007 - 09:28 AM
User is offlineProfile CardPM
+Quote Post

rockstar_
RE: Never Programmed B4. Please Help!
28 Nov, 2007 - 01:35 PM
Post #6

D.I.C Head
Group Icon

Joined: 16 Oct, 2006
Posts: 187


Dream Kudos: 275
My Contributions
Just so you know, it is imperative that you use the code tags in the forum when you're posting python code. The whitespace is quite needed. Anyway, your problem is in your Book class. It should appear like this, with the additional displayInfo() method.
CODE
class Book:

  def __init__ (self,pubtitle,pubgenre,bookpages):
    Publication.__init__(self,pubtitle,pubgenre)  # <-- you're creating an object and immediately killing it, because it's not being stored anywhere
    return  #<-- You also don't need to return anything here

  def displayInfo():
    print 'This is the displayInfor() method'

Right now, you're trying to call a method that doesn't exist
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 11:13PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month