Python 实训3 简单的好友通讯录管理程序

Python 实训3 简单的好友通讯录管理程序_第1张图片
Python 实训3 简单的好友通讯录管理程序_第2张图片
在这里插入图片描述

答案源码:

address_book = {
    '小明':['001','广州'],
    '小红':['002','深圳'],
    '小王':['003','北京']
}
tip = """
添加好友请输入1
删除好友请输入2
修改好友信息请输入3
查询好友信息请输入4
"""
print(tip)
num = input("请输入数字:")
int_num = int(num)
if(int_num==1):
    str = input("请输入好友信息,姓名电话地址,以空格分开:")
    name = str.split( )[0]
    info = str.split( )
    info.pop(0)
    address_book[name] = info
    print(address_book)
elif(int_num==2):
    name = input("请输入要删除好友的姓名:")
    del address_book[name]
    print(address_book)
elif(int_num==3):
    name = input("请输入修改好友的姓名:")
    numb = input("要修改电话号码请输入1,修改地址请输入2,如需都修改请输入3:")
    int_numb = int(numb)
    if(int_numb==1):
        new_phone = input("请输入号码:")
        list_info = address_book.get(name)
        address_book = {name:[new_phone,list_info[1]]}
        print(address_book)
    elif(int_numb==2):
        new_address = input("请输入地址:")
        list_info = address_book.get(name)
        address_book = {name:[list_info[0],new_address]}
        print(address_book)
    elif(int_numb==3):
        newinfo = input("请输入号码和地址,并以空格分开:")
        str = newinfo.split( )
        address_book = {name:[str[0],str[1]]}
        print(address_book)
    else:
        print("请输入正确数字!")
elif(int_num==4):
    name = input("请输入要查询的好友姓名:")
    print(address_book[name])
else:
    print("请输入正确数字!")

程序逻辑很清楚,运行结果就不在此展示了,你可以复制一下自己运行。

拿到答案了,点个赞呗~哈哈哈

你可能感兴趣的:(Python)