728x90
응용문제 2 : 주소록 만들기
문제
이름과 전화번호를 딕셔너리로 구성
1. 전체조회 : 주소록 모든 정보를 출력한다.
2. 조회기능 : 이름을 입력하면 이름, 전화번호가 출력된다.
3. 추가기능 : 새로운 친구의 이름과 전화번호를 등록한다.
4. 수정기능 : 친구 전화번호를 수정한다.
5. 삭제기능 : 친구 목록을 삭제한다.
6. 전체 친구의 수를 출력한다.
7. 전체 친구의 이름을 출력한다.
#1 전체조회
phone={'a':'010-2332-4453' ,'b':'010-1323-1234', 'c':'010-1524-1253'}
#2 조회기능
name=input('name:')
#print(name,phone[name])
print(name, phone.get(name,'not Found'))
# 3. 추가기능
name=input('insert name:')
tel=input('phone number:')
phone[name]=tel
#phone.setdefault(name,tel)
print('추가', phone)
# 4. 수정기능
name=input('name:')
tel=input('number:')
phone[name]=tel
print('수정', phone)
# 5. 삭제기능
name=input('delete:')
del(phone[name])
print('삭제',phone)
# ## 다른 버전 삭제기능
# name=input('delete name:')
# phone.pop(name)
# print('삭제', phone)
#6 전체 친구의 수
len(phone)
#7 전체 친구의 이름 출력
namelist=list(phone.keys())
print(namelist)
phone
728x90
'💻 Programming > Python' 카테고리의 다른 글
[Python] 과제 10주차 (0) | 2023.01.08 |
---|---|
[Python] 과제 9주차 (0) | 2023.01.08 |
[Python] 과제 7주차 (0) | 2023.01.07 |
[Python] 과제 6주차 (0) | 2023.01.07 |
[Python] 과제 3주차 (0) | 2022.03.28 |