#전화번호부
class PhoneBook:
def __init__(self,name,phone):
self.name = name
self.phone = phone
def info(self):
print('name:',self.name)
print('phone:',self.phone)
class PbManager:
phoneList=[]
def search():
if len(PbManager.phoneList)<=0:
print('검색할 정보가 없습니다')
return
else:
searchName = input('찾을 이름:')
for i in range(len(PbManager.phoneList)):
if PbManager.phoneList[i].name == searchName:
print('검색한 전화번호:',PbManager.phoneList[i].phone)
return
print('찾으시는 전화번호가 없습니다')
def show():
if len(PbManager.phoneList)<=0:
print('출력할 정보가 없습니다')
return
else:
for i in PbManager.phoneList:
i.info()
def update():
if len(PbManager.phoneList)<=0:
print('수정할 정보가 없습니다')
return
else:
updateName = input('수정할 사람의 이름:')
for i in range(len(PbManager.phoneList)):
if PbManager.phoneList[i].name == updateName:
print('현재번호:',PbManager.phoneList[i].phone)
updatePhone = input('수정할 번호:')
PbManager.phoneList[i].phone = updatePhone
print('수정완료')
return
print('해당 이름의 정보가 존재하지 않습니다.')
def save():
name = input('이름:')
phone = input('전화번호:')
#입력값으로 객체를 생성
newPhonebook=PhoneBook(name,phone)
#생성한 객체를 객체리스트에 추가
PbManager.phoneList.append(newPhonebook)
def delete():
if len(phoneList)<=0:
print('삭제할 정보가 없습니다')
return
#PbManager.save()
while True:
print('☆★☆★PhoneBook☆★☆★')
print('1. 저장하기')
print('2. 출력하기')
print('3. 검색하기')
print('4. 수정하기')
print('5. 삭제하기')
print('6. 끝내기')
sc = int(input('입력:'))
if sc == 1:
PbManager.save()
elif sc == 2:
PbManager.show()
elif sc == 3:
PbManager.search()
elif sc == 4:
PbManager.update()
elif sc == 5:
PbManager.delete()
elif sc == 6:
print('프로그램 종료')
break
else:
print('잘못입력하셧습니다')
이름
전화번호
검색()
저장()
수정()
삭제()
조회()
프로그래밍/Python
예제- 전화번호부
반응형
반응형