Go Down

Topic: i have some issues with 'Python-Classes  (Read 265 times) previous topic - next topic

apollodriver

May 01, 2019, 12:27 pm Last Edit: May 01, 2019, 02:01 pm by apollodriver
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 assignment we have to do. to go further -. what was done this code and I'm not entirely sure where to go from there.
Code: [Select]

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
Code: [Select]

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

def __init__(self):
    pass


    That does not do what the instructions want.

Also:

Code: [Select]
def getName(self):
    return self.name
def getNumber(self):
    return self.number


   
should i  really use getters in python?
WPGear.org is a compendium of useful developer tools for working with WordPress.

PaulS

Quote
hello dear Raspi-Experts
You seem to be lost. This is not the Raspberry Pi, or Python, forum.
The art of getting good answers lies in asking good questions.

UKHeliBob

Quote
Design a Python class for a Phonebook.
Good luck with your assignment
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

srnet

one question: can someone give me some hints
Ask in a Python or Raspberry Pi Forum for help with Python or Raspberry Pi.
Co-Designer of the worlds smallest (known) operational satellite, $50SAT.
http://www.50dollarsat.info/
http://www.loratracker.uk/

apollodriver

good day dear friends,



many many thanks for the quick reply.  Thaniks for the tipps. I will do as adviced and do some more research.

Have a great day.

greetings
your apollodriver
WPGear.org is a compendium of useful developer tools for working with WordPress.

Go Up