pythons手机通讯录
时间: 2023-11-20 19:58:16 浏览: 110
以下是一个简单的Python手机通讯录的例子:
```python
contacts = {} # 创建一个空字典,用于存储联系人信息
# 添加联系人
def add_contact():
name = input("请输入联系人的姓名:")
phone = input("请输入联系人的手机号:")
email = input("请输入联系人的邮箱:")
address = input("请输入联系人的地址:")
contacts[name] = {"phone": phone, "email": email, "address": address}
print("保存成功")
# 查看通讯录
def view_contacts():
if not contacts:
print("通讯录为空")
else:
for name, info in contacts.items():
print("姓名:", name)
print("手机号:", info["phone"])
print("邮箱:", info["email"])
print("地址:", info["address"])
print("--------------------")
# 删除联系人
def delete_contact():
name = input("请输入要删除的联系人姓名:")
if name in contacts:
del contacts[name]
print("删除成功")
else:
print("联系人不存在")
# 修改联系人
def modify_contact():
name = input("请输入要修改的联系人姓名:")
if name in contacts:
phone = input("请输入联系人的手机号:")
email = input("请输入联系人的邮箱:")
address = input("请输入联系人的地址:")
contacts[name] = {"phone": phone, "email": email, "address": address}
print("修改成功")
else:
print("联系人不存在")
# 查找联系人
def search_contact():
name = input("请输入要查找的联系人姓名:")
if name in contacts:
info = contacts[name]
print("姓名:", name)
print("手机号:", info["phone"])
print("邮箱:", info["email"])
print("地址:", info["address"])
else:
print("联系人不存在")
# 主程序
while True:
print("====================")
print("欢迎使用通讯录:")
print("1.添加联系人")
print("2.查看通讯录")
print("3.删除联系人")
print("4.修改联系人")
print("5.查找联系人")
print("6.退出")
print("====================")
choice = input("请输入功能序号:")
if choice == "1":
add_contact()
elif choice == "2":
view_contacts()
elif choice == "3":
delete_contact()
elif choice == "4":
modify_contact()
elif choice == "5":
search_contact()
elif choice == "6":
break
else:
print("输入有误,请重新输入")
```
阅读全文