简单的字符串匹配
import sys
commands = {
("reset", "board"): "board fault",
("board", "add"): "where to add",
("board", "delete"): "no board at all",
("reboot", "backplane"): "impossible",
("backplane", "abort"): "install first",
}
for line in sys.stdin:
a = line.split()
if len(a) == 1:
if "reset".startswith(a[0]):
print("reset what")
else:
print("unknown command")
elif len(a) == 2:
results = []
for each in commands:
if each[0].startswith(a[0]) and each[1].startswith(a[1]):
results.append(commands[each])
if len(results) == 1:
print(results[0])
else:
print("unknown command")
else:
print("unknown command")



京公网安备 11010502036488号