friends_list = [] print('欢迎使用好友管理系统') print('1. 添加好友') print('2. 删除好友') print('3. 备注好友') print('4. 展示好友') print('5. 退出\n')

while True: choice = input('请输入您的选项:') if choice == '1': name = input('请输入要添加的好友姓名:') if name in friends_list: print('该好友已存在') else: friends_list.append(name) print('添加成功') elif choice == '2': name = input('请输入要删除的好友姓名:') if name in friends_list: friends_list.remove(name) print('删除成功') else: print('该好友不存在') elif choice == '3': name = input('请输入要修改的好友姓名:') if name in friends_list: index = friends_list.index(name) rename = input('请输入修改后的好友姓名:') friends_list[index] = rename print('修改成功') else: print('该好友不存在') elif choice == '4': for friend in friends_list: print(friend, end=' ') print() elif choice == '5': print('系统已退出') break else: print('输入错误,请重新输入选项:')

Python 好友管理系统:代码实现与优化

原文地址: https://www.cveoy.top/t/topic/zYY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录