Python 好友管理系统代码:用英语表达功能菜单
friends_list = [] print('Welcome to the Friend Management System') print('1. Add friend') print('2. Delete friend') print('3. Remark friend') print('4. Show friends') print('5. Quit\n')
while True: choice = input('Please enter your option:') if choice == '1': name = input('Please enter the name of the friend to add:') if name in friends_list: print('This friend already exists') else: friends_list.append(name) print('Added successfully') elif choice == '2': name = input('Please enter the name of the friend to delete:') if name in friends_list: friends_list.remove(name) print('Deleted successfully') else: print('This friend does not exist') elif choice == '3': name = input('Please enter the name of the friend to modify:') if name in friends_list: index = friends_list.index(name) rename = input('Please enter the new name for the friend:') friends_list[index] = rename print('Modified successfully') else: print('This friend does not exist') elif choice == '4': for i in range(len(friends_list)): print(friends_list[i], end=' ') print() elif choice == '5': print('System has exited') break else: print('Input error, please re-enter the option:')
原文地址: https://www.cveoy.top/t/topic/zYr 著作权归作者所有。请勿转载和采集!