Python朋友管理系统
时间: 2023-12-05 11:39:28 浏览: 88
以下是一个简单的Python好友管理系统的示例:
```python
def add_friend(friends):
name = input("请输入要添加的好友:")
friends.append(name)
print("好友添加成功")
def delete_friend(friends):
name = input("请输入删除好友姓名:")
if name in friends:
friends.remove(name)
print("删除成功")
else:
print("好友不存在")
def modify_friend(friends):
old_name = input("请输入要修改的好友姓名:")
if old_name in friends:
new_name = input("请输入修改后的好友姓名:")
index = friends.index(old_name)
friends[index] = new_name
print("备注成功")
else:
print("好友不存在")
def show_friends(friends):
if len(friends) == 0:
print("好友列表为空")
else:
for friend in friends:
print(friend)
def friend_management():
friends = []
while True:
print("请输入您的选项:")
print("1. 添加好友")
print("2. 删除好友")
print("3. 备注好友")
print("4. 展示好友")
print("5. 退出")
option = input()
if option == "1":
add_friend(friends)
elif option == "2":
delete_friend(friends)
elif option == "3":
modify_friend(friends)
elif option == "4":
show_friends(friends)
elif option == "5":
break
else:
print("无效的选项")
friend_management()
```
阅读全文