python好友管理系统
时间: 2023-10-13 08:23:12 浏览: 67
好的,一个简单的 Python 好友管理系统可以包括以下功能:
1. 添加好友:输入好友的姓名、电话号码和备注等信息,将好友添加到系统中。
2. 删除好友:根据好友的姓名或电话号码,从系统中删除好友信息。
3. 修改好友信息:根据好友的姓名或电话号码,修改好友的电话号码、备注等信息。
4. 查找好友:根据好友的姓名或电话号码,查找好友的详细信息。
5. 显示所有好友:将系统中所有好友的信息全部显示出来。
下面是一个简单的 Python 好友管理系统的代码示例:
```python
# 定义一个空字典,用于存储好友信息
friends = {}
# 添加好友
def add_friend():
name = input("请输入好友姓名:")
phone = input("请输入好友电话号码:")
remark = input("请输入好友备注:")
friends[name] = {"phone": phone, "remark": remark}
print("好友添加成功!")
# 删除好友
def delete_friend():
name_or_phone = input("请输入好友姓名或电话号码:")
if name_or_phone in friends:
del friends[name_or_phone]
print("好友删除成功!")
else:
for friend in friends.values():
if friend["phone"] == name_or_phone:
del friends[friend["name"]]
print("好友删除成功!")
break
else:
print("未找到该好友!")
# 修改好友信息
def modify_friend():
name_or_phone = input("请输入好友姓名或电话号码:")
if name_or_phone in friends:
friend = friends[name_or_phone]
phone = input("请输入好友电话号码:")
remark = input("请输入好友备注:")
friend["phone"] = phone
friend["remark"] = remark
print("好友信息修改成功!")
else:
for friend in friends.values():
if friend["phone"] == name_or_phone:
phone = input("请输入好友电话号码:")
remark = input("请输入好友备注:")
friend["phone"] = phone
friend["remark"] = remark
print("好友信息修改成功!")
break
else:
print("未找到该好友!")
# 查找好友
def find_friend():
name_or_phone = input("请输入好友姓名或电话号码:")
if name_or_phone in friends:
friend = friends[name_or_phone]
print("好友姓名:", name_or_phone)
print("好友电话号码:", friend["phone"])
print("好友备注:", friend["remark"])
else:
for friend in friends.values():
if friend["phone"] == name_or_phone:
print("好友姓名:", friend["name"])
print("好友电话号码:", name_or_phone)
print("好友备注:", friend["remark"])
break
else:
print("未找到该好友!")
# 显示所有好友
def show_friends():
if friends:
print("好友列表:")
for name, friend in friends.items():
print("姓名:", name)
print("电话号码:", friend["phone"])
print("备注:", friend["remark"])
else:
print("好友列表为空!")
# 主函数
def main():
while True:
print("==================")
print("1. 添加好友")
print("2. 删除好友")
print("3. 修改好友信息")
print("4. 查找好友")
print("5. 显示所有好友")
print("6. 退出系统")
print("==================")
choice = input("请输入功能编号:")
if choice == "1":
add_friend()
elif choice == "2":
delete_friend()
elif choice == "3":
modify_friend()
elif choice == "4":
find_friend()
elif choice == "5":
show_friends()
elif choice == "6":
print("感谢使用好友管理系统,再见!")
break
else:
print("输入有误,请重新输入!")
if __name__ == '__main__':
main()
```
运行程序后,可以根据提示进行相应的操作。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)