contact = {}
while True : 
    print('======연락처 프로그램======')
    print('''
    1. 추가 2. 목록보기 3. 검색 4. 수정 5. 삭제 9. 종료
    ===================================================
    ''')
    menu = int(input('메뉴 선택:'))
    if menu == 1:
        print('연락처 추가 작업')
        name = input('이름:')
        tel = input('전화번호:')
        contact.setdefault(name, tel) #딕셔너리에 요소 추가 하는 것
        print('추가 작업 완료')
    elif menu == 2:
        print('연락처 목록보기')
        for i, j in contact.items():
            print(i,':',j)
    elif menu == 3:
        print('연락처 검색')
        name = input('검색할 이름:')
        if name in contact:
            tel = contact[name]
            print(name, ':', tel)        
        else:
            print('등록되지 않은 이름입니다!')
    elif menu == 4:
        print('연락처 수정')
        name = input('수정할 이름:')
        if name not in contact:
            print('등록되지 않은 이름입니다!')
        else:
            tel = input('새 전화번호:')
            contact[name]= tel
            print('수정 작업 완료')
    elif menu == 5:
        print('연락처 삭제')
        name = input('삭제할 이름:')
        if name in contact:
            contact.pop(name) #삭제 
            print('삭제 작업 완료')
        else :
            print('등록되지 않은 이름입니다!')
    elif menu == 9:
        print('프로그램을 종료합니다!')
        break

+ Recent posts