Oct-29-2018, 10:38 PM
hello dear all,
fairly new to python
with this little script i am trying to learn some steps reagarding oo programming.
i want to extend this little script to gather some more information:
Again:
what is wanted... to gather information regarding
fairly new to python
with this little script i am trying to learn some steps reagarding oo programming.
i want to extend this little script to gather some more information:
01 #!/usr/bin/env python3 02 """ 03 contacts.py 04 This program uses a Person class to keep track of contacts. 05 """ 06 07 class Person(object): 08 """ 09 The Person class defines a person in terms of a 10 name, phone number, and email address. 11 """ 12 # Constructor 13 def __init__(self, theName, thePhone, theEmail): 14 self.name = theName 15 self.phone = thePhone 16 self.email = theEmail 17 # Accesser Methods (getters) 18 def getName(self): 19 return self.name 20 def getPhone(self): 21 return self.phone 22 def getEmail(self): 23 return self.email 24 # Mutator Methods (setters) 25 def setPhone(self, newPhoneNumber): 26 self.phone = newPhoneNumber 27 def setEmail(self, newEmailAddress): 28 self.email = newEmailAddress 29 def __str__(self): 30 return "Person[name=" + self.name + \ 31 ",phone=" + self.phone + \ 32 ",email=" + self.email + \ 33 "]" 34 35 def enter_a_friend(): 36 name = input("Enter friend's name: ") 37 phone = input("Enter phone number: ") 38 email = input("Enter email address: ") 39 return Person(name, phone, email) 40 41 def lookup_a_friend(friends): 42 found = False 43 name = input("Enter name to lookup: ") 44 for friend in friends: 45 if name in friend.getName(): 46 print(friend) 47 found = True 48 if not found: 49 print("No friends match that term") 50 51 def show_all_friends(friends): 52 print("Showing all contacts:") 53 for friend in friends: 54 print(friend) 55 56 def main(): 57 friends = [] 58 running = True 59 while running: 60 print("\nContacts Manager") 61 print("1) new contact 2) lookup") 62 print("3) show all 4) end ") 63 option = input("> ") 64 if option == "1": 65 friends.append(enter_a_friend()) 66 elif option == "2": 67 lookup_a_friend(friends) 68 elif option == "3": 69 show_all_friends(friends) 70 elif option == "4": 71 running = False 72 else: 73 print("Unrecognized input. Please try again.") 74 print("Program ending.") 75 76 if __name__ == "__main__": 77 main() 78 79what is wanted... to gather information regarding
# Constructor def __init__(self, theName, thePhone, theEmail, theAdress, ): self.name = theName self.phone = thePhone self.email = theEmail self.Adress = theAdressbut untill now i have no luck... i only am able to gather inforamtion about the following aspects
# Constructor def __init__(self, theName, thePhone, theEmail, theAdress, ? self.name = theName self.phone = thePhone self.email = theEmailand the newly added adress - it does not get in effect..
self.Adress = theAdress- see my approach:
#!/usr/bin/env python3 """ contacts.py This program uses a Person class to keep track of contacts. @author Richard White @version 2016-07-30 """ class Person(object): """ The Person class defines a person in terms of a name, phone number, and email address. """ # Constructor def __init__(self, theName, thePhone, theEmail, theAdress, ): self.name = theName self.phone = thePhone self.email = theEmail self.adress = theAdress # Accesser Methods (getters) def getName(self): return self.name def getPhone(self): return self.phone def getEmail(self): return self.email def getAdress(self): return self.adress; # Mutator Methods (setters) def setPhone(self, newPhoneNumber): self.phone = newPhoneNumber def setEmail(self, newEmailAddress): self.email = newEmailAddress def __str__(self): return "Person[name=" + self.name + \ ",phone=" + self.phone + \ ",email=" + self.email + \ ",adress=" + self.adress + \ "]" def enter_a_friend(): name = input("Enter friend's name: ") phone = input("Enter phone number: ") email = input("Enter email address: ") return Person(name, phone, email) def lookup_a_friend(friends): found = False name = input("Enter name to lookup: ") for friend in friends: if name in friend.getName(): print(friend) found = True if not found: print("No friends match that term") def show_all_friends(friends): print("Showing all contacts:") for friend in friends: print(friend) def main(): friends = [] running = True while running: print("\nContacts Manager") print("1) new contact 2) lookup") print("3) show all 4) end ") option = input("> ") if option == "1": friends.append(enter_a_friend()) elif option == "2": lookup_a_friend(friends) elif option == "3": show_all_friends(friends) elif option == "4": running = False else: print("Unrecognized input. Please try again.") print("Program ending.") if __name__ == "__main__": main()well - i guess that i have to look and i have to try to find out what goes wrong...
Again:
what is wanted... to gather information regarding
# Constructor def __init__(self, theName, thePhone, theEmail, theAdress, ): self.name = theName self.phone = thePhone self.email = theEmail self.Adress = theAdressbut untill now i have no luck... i only am able to gather inforamtion about the following aspects
# Constructor def __init__(self, theName, thePhone, theEmail, theAdress, ? self.name = theName self.phone = thePhone self.email = theEmailand the newly added adress - it does not get in effect..
self.Adress = theAdresslove to hear from you