Python代码,识别动物明明输入了黑色条纹的条件依然识别为金钱豹,其他的也是这样,问一下是怎么回事
fp1 = open("features.txt", encoding='UTF-8')
lines1 = fp1.readlines()
leng = len(lines1)
def rules():
test = 1
list3 = list2.copy()
while test == 1:
test = 0
if ("有毛发" in list3 or "有奶" in list3) and "哺乳动物" not in list3:
print("使用规则:有毛发 or 有奶-->哺乳动物")
test = 1
list3.append("哺乳动物")
print("当前动态数据库:", list3)
elif "有羽毛" in list3 and "鸟" not in list3:
print("使用规则:有羽毛-->鸟")
test = 1
list3.append("鸟")
print("当前动态数据库:", list3)
elif "会飞" in list3 and "会下蛋" in list3 and "鸟" not in list3:
print("使用规则:会飞 and 会下蛋 --> 鸟")
test = 1
list3.append("鸟")
print("当前动态数据库:", list3)
elif "吃肉" in list3 and "食肉动物" not in list3:
print("使用规则:吃肉-->食肉动物")
test = 1
list3.append("食肉动物")
print("当前动态数据库:", list3)
elif "有犬齿" in list3 and "有爪" in list3 and "眼盯前方" in list3 and "食肉动物" not in list3:
print("使用规则:有犬齿 and 有爪 and 眼盯前方-->食肉动物")
test = 1
list3.append("食肉动物")
print("当前动态数据库:", list3)
elif "哺乳动物" and "有蹄" in list3 and "蹄类动物" not in list3:
print("使用规则:哺乳动物 and 有蹄-->蹄类动物")
test = 1
list3.append("蹄类动物")
print("当前动态数据库:", list3)
elif "哺乳动物" and "反刍动物" in list3 and "反刍动物" not in list3:
print("使用规则:哺乳动物 and 反刍动物-->蹄类动物")
test = 1
list3.append("蹄类动物")
print("当前动态数据库:", list3)
elif "哺乳动物" in list3 and "食肉动物" in list3 and "黄褐色" in list3 and "暗斑点" in list3:
print("使用规则:哺乳动物 and 食肉动物 and 黄褐色 and 暗斑点 -->金钱豹")
list3.append("金钱豹")
test = 1
print("当前动态数据库:", list3)
return list3[-1]
elif "哺乳动物" in list3 and "食肉动物" in list3 and "黄褐色" in list3 and "黑色条纹" in list3:
print("使用规则:哺乳动物 and 食肉动物 and 黄褐色 and 黑色条纹 -->虎")
list3.append("虎")
test = 1
print("当前动态数据库:", list3)
return list3[-1]
elif "蹄类动物" in list3 and "长脖子" in list3 and "长腿" in list3 and "暗斑点" in list3:
print("使用规则:蹄类动物 and 长脖子 and 长腿 and 暗斑点 -->长颈鹿")
list3.append("长颈鹿")
test = 1
print("当前动态数据库:", list3)
return list3[-1]
elif "蹄类动物"in list3 and "黑色条纹" in list3:
print("使用规则:蹄类动物 and 黑色条纹 -->斑马")
list3.append("斑马")
test = 1
print("当前动态数据库:", list3)
return list3[-1]
elif "鸟"in list3 and "长脖子"in list3 and "长腿"in list3 and "不会飞"in list3 and "有黑白二色"in list3:
print("使用规则:鸟 and 长脖子 and 长腿 and 不会飞 and 有黑白二色 -->鸵鸟")
list3.append("鸵鸟")
test = 1
print("当前动态数据库:", list3)
return list3[-1]
elif "鸟"in list3 and "会游泳"in list3 and "不会飞"in list3 and "有黑白二色" in list3:
print("使用规则:鸟 and 会游泳 and 不会飞 and 有黑白二色 -->企鹅")
list3.append("企鹅")
test = 1
print("当前动态数据库:", list3)
return list3[-1]
elif "鸟"in list3 and "善飞" in list3:
print("使用规则:鸟 and 善飞 -->信天翁")
list3.append("信天翁")
test = 1
print("当前动态数据库:", list3)
return list3[-1]
else:
print("匹配错误")
return 0
print("----------知识数据库如下----------")
i = 0
list1 = []
list2 = []
for line in lines1:
line = line.strip('\n')
list1.append(line)
if i == leng - 1:
break
print("{}:{}".format(i, line))
i += 1
choice1 = input("请输入已知知识序号并以空格隔开")
temp = choice1.split(" ")
print("选中的事