题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
key=["reset","reset board","board add","board delete","reboot backplane","backplane abort"] value=["reset what","board fault","where to add","no board at all","impossible","install first"] dic = {} for i in range(len(key)): dic[key[i]] = value[i] while True: try: m=input().strip().split() if len(m)<1 or len(m)>2: #判断当输入为小于1个或者输入大于2个字符串时,不符合命令,就报未知命令 print("unknown command") elif len(m)==1: if key[0].startswith(m[0]): print(value[0]) else: print("unknown command") elif len(m)==2: flag = 0 for i in range(1,len(key)): t1 = key[i].split()[0] t2 = key[i].split()[1] if t1.startswith(m[0]) and t2.startswith(m[1]): flag +=1 f = value[i] if flag ==1: print(f) else: print("unknown command") except: break