import sys
features = ["", "有毛发", "有奶", "有羽毛", "会飞", "会下蛋", "吃肉", "有犬齿", "有爪","眼盯前方", "有蹄", "嚼反刍", "黄褐色", "身上有暗斑点", "身上有黑色条纹", "有长脖子", "有长腿", "不会飞", "会游泳", "有黑白二色", "善飞", "哺乳动物", "鸟", "食肉动物", "蹄类动物", "金钱豹", "虎", "长颈鹿", "斑马", "鸵鸟", "企鹅", "信天翁"]
# print('请选择您要进行的操作:\n'
# '1 识别动物\n'
# '2 增加特征\n'
# '3 增加动物\n'
# '4 修改特征条件\n')
# select = input('请输入编号,回车结束:')
# 应该把特征和动物名称分成两个列表
print('以下是一些动物的特征:')
print('\n')
i = 1
while i < 25:
print('%d' %i +'.'+ features[i]+ ' ', end='')
i = i+1
if i % 4 == 1:
print('\n')
print('\n')
answer = input('请选择动物的特征编号,用英文逗号分开,回车结束输入:')
# 接收到的answer是一个字符串
try:
answer = list(answer.split(','))
new_answer = [int(x) for x in answer]
# print(new_answer)
except Exception:
print('您输入的是数字么?或者,逗号不是英文的?')
sys.exit()
rule1 = [2]
rule2 = [1]
rule3 = [3]
rule4 = [4, 5]
rule5 = [8, 7, 9]
rule6 = [6]
rule7 = [21, 10]
rule8 = [21, 11]
rule9 = [21, 23, 12, 14]
rule10 = [21, 23, 12, 13]
rule11 = [24, 15, 16, 13]
rule12 = [24, 14]
rule13 = [22, 17, 16, 15, 19]
rule14 = [22, 17, 18, 19]
rule15 = [22, 4]
if new_answer == rule1:
print(features[21])
elif new_answer == rule2:
print(features[21])
elif new_answer == rule3:
print(features[22])
elif new_answer == rule4:
print(features[22])
elif new_answer == rule5:
print(features[23])
elif new_answer == rule6:
print(features[23])
elif new_answer == rule7:
print(features[24])
elif new_answer == rule8:
print(features[24])
elif new_answer == rule9:
print(features[26])
elif new_answer == rule10:
print(features[25])
elif new_answer == rule11:
print(features[27])
elif new_answer == rule12:
print(features[28])
elif new_answer == rule13:
print(features[29])
elif new_answer == rule14:
print(features[30])
elif new_answer == rule15:
print(features[31])
else:
print('识别失败!')
# print(new_answer)
# for i in new_answer:
# print(features[i])
# if new_answer in dict_animal.keys():
# print('yes')
# print(dict_animal[new_answer])
# print(features[dict_animal[new_answer]])
用python实现了基本功能,但还有很多不足之处,待续…