Jump to content

issues with classes in Python


Recommended Posts

hello dear Experts 

i am going to create a Phonebook class

efforts and parts: Design a Python class for a Phonebook. You class should have the following methods - see the little list that i have to implement: 

init (self): creates an empty list to store names and numbers
Add(self, name, number): adds the name and number to the list
Display(self): displays the entire phonebook.
Find(self, name): this should find and also do the print of the number in the little phonebook that is associated with the name

last but not least i want to add more stuff: eg. 
Add a main() method that ddoes more - eg. to the script that adds a couple of new phone entries and calls the display() and besides of this additionaly find() methods to see if they work.

so far so good: That's the sum of ideas i want to implement. to go further -. what was done this code and I'm not entirely sure where to go from there.

class Phonebook:
	def __init__(self):
    pass
def add(self,name, number):
    self.name=name
    self.numbers=number
	def getName(self):
    return self.name
def getNumber(self):
    return self.number
	def find(self, name):
    a = raw_input("What is their First Name?")
    return(self,name)
     
def display(self):
    return display
def main(): phone1 = Phonebook("foo bar", 13345444234214) phone2 = Phonebook("foo bar", 13345444234214)
print(display())
if name == 'main': main()


well  what was done this code and I'm not entirely sure where to go from there.

one question: can someone give me some hints - I've tried looking in books and tried to find out how to use the add function and, 
The question is: how to incorpoate find and display in the def main function. Thanks


i guess that 

__init__(self): creates an empty list to store names and numbers
def __init__(self):
    pass

    That does not do what the instructions want.

Also:

def getName(self):
    return self.name
def getNumber(self):
    return self.number
	

 
   
should i  really use getters in python?
[

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.