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?

5 Years
Discussion Span
Last Post by woooee
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?

Edited by jone kim


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
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.