题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
command = {} command.update({'reset': 'reset what', 'reset board': 'board fault', 'board add': 'where to add', 'board delete': 'no board at all', 'reboot backplane': 'impossible', 'backplane abort': 'install first' }) cmd_list = ['reset board', 'board add', 'board delete', 'reboot backplane', 'backplane abort'] while True: try: cmd = input().strip(' ') if cmd.count(' ') == 0: if cmd == 'reset'[:len(cmd)]: print('reset what') else: print('unknown command') elif cmd.count(' ') == 1: match_list = [] for i in cmd_list: if cmd.split(' ')[0] == i.split(' ')[0][:len(cmd.split(' ')[0])] and cmd.split(' ')[1] == i.split(' ')[1][:len(cmd.split(' ')[1])]: match_list.append(i) if len(match_list) == 1: print(command[match_list[0]]) else: print('unknown command') else: print('unknown command') except: break