파이썬 전화번호부 클래스
조회수 1869회
전화번호부 코드를 클래스를 이용하여 작성중입니다.
딕셔너리를 이용해서 연락처 저장할 수 있도록 하고 있는데요 연락처를 계속 추가할수 있도록 하려고 합니다!
어느정도는 했는데 자꾸 오류나서 부분만 올려봅니다 도움 부탁드립니다.
class Person():
def __init__(self, name, mobile=None, office=None, email=None):
def setMobile(self, number):
def setOffice(self, number):
def setEmail(self, address):
def __str__(self):
s = ''
s += self.name + '\n'
s += "office phone:"+self.office + '\n'
s += "email address:"+self.email + '\n'
return s
class PhoneBook():
def __init__(self):
self.contacts = {}
def add(self, name, mobile=None, office=None, email=None):
def __str__(self):
s = ''
for p in sorted(self.contacts):
s += str(self.contacts[p]) + '\n'
return s
obj = PhoneBook()
obj.add("Kim", office="1234567", email="kim@company.com")
obj.add("Park", office="2345678", email="park@company.com")
print(obj)
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
댓글 입력