I want to design:
1. address class ->using dictionary data structure where items are; state, city and street for individual person
2. name class -> person's first and last name
3. display class -> searches for the given name and displays the address of that particular name

my questions are:
1. how to design the address class such that it takes name of the person from the name class and stores the address info. in a dictionary?
2. how to make search for the name and display of the address information?

Recommended Answers

All 3 Replies

Post your best try so far and then we can give you help with it.

class name:
def __init__(self, firstName, lastName):
    self.firstName = firstName
    self.lastName = lastName

class address(name):
def __init__(self):
    super.__init__(firstName, lastName)
    self.completeAddress = {
        "state": self.state,
        "city": self.city,
        "street": self.street

class search:
print("enter the firstname or lastname or complete name seperated by space of the person: ")

My problems are now:

  1. if the user enters the firstName, it should return all the address related to the firstName
  2. if the user enters the lastName, it should return all the address related to that lastName
  3. if the user enters completeName, the search class should take both firstName and lastName and give the result, is it possible?

You don't need two classes for this unless one person can have multiple addresses. You would store each class instance in a list and iterate through the list to find names: example

for instance in list_of_instances:
    if instance.firstName=="Bob":
        print instance.firstName, instance.lastName
        print instance.street, instance.city, instance.state
        print "Bob is not on file
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.