题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
while True: try: command = input().split(' ') dict_command = { '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', 'other': 'unknown command' } keys_list = [] for key in dict_command.keys(): keys_list.append(key.split(' ')) # print(keys_list) if len(command) == 1: if command[0] in 'reset': print(dict_command['reset']) else: print(dict_command['other']) elif len(command) == 2: count = 0 for key in keys_list[1:-1]: if key[0].startswith(f'{command[0]}'): if key[1].startswith(f'{command[1]}'): command_key = key[0] + ' ' + key[1] # print(command_key) count += 1 if count == 1: print(dict_command[f'{command_key}']) else: print(dict_command['other']) else: print(dict_command['other']) except: break