Python Friend Management System: Add, Delete, Rename, and Display Friends
friends_list = [] print('Welcome to the Friend Management System') print('1. Add Friend') print('2. Delete Friend') print('3. Rename Friend') print('4. Display Friends') print('5. Quit ')
while True: choice = input('Please enter your choice:') 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('Successfully added') elif choice == '2': name = input('Please enter the name of the friend to delete:') if name in friends_list: friends_list.remove(name) print('Successfully deleted') else: print('This friend does not exist') elif choice == '3': name = input('Please enter the name of the friend to rename:') 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('Successfully renamed') 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('Invalid input, please enter a valid option:')
原文地址: https://www.cveoy.top/t/topic/zXO 著作权归作者所有。请勿转载和采集!