Skip to content

Commit ad3af26

Browse files
committed
专家系统
1 parent 33e2e45 commit ad3af26

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

expert_system.py

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
3+
def first_feature():
4+
"""
5+
选择特征确定动物类别
6+
:return: 动物类别: int
7+
"""
8+
print('1恒温且有脊椎;2有羽毛且卵生;3有鳞片/角质层且三心室')
9+
choice = input('请选择特征')
10+
return int(choice)
11+
12+
def specific_feature(choice):
13+
"""
14+
输入动物类别,再选择动物特征,确定具体动物类别
15+
:param choice: int
16+
:return: 具体动物: str
17+
"""
18+
if choice == 1:
19+
mammal()
20+
elif choice == 2:
21+
bird()
22+
elif choice == 3:
23+
reptile()
24+
else:
25+
print('输入无效,无法确定动物类别')
26+
27+
def mammal():
28+
"""
29+
确定是哺乳动物,继续选择特征,确定具体动物
30+
:return: 无
31+
"""
32+
print('该动物是哺乳动物')
33+
print()
34+
print('1能捕鼠;2有黑色斑点;3生活在海洋')
35+
choice = int(input('请继续从上面特征中进行选择'))
36+
if choice == 1:
37+
print('该动物是猫')
38+
elif choice == 2:
39+
print('该动物是豹')
40+
elif choice == 3:
41+
print('该动物是鲸')
42+
else:
43+
print('输入无效,无法确定具体动物')
44+
45+
def bird():
46+
"""
47+
确定是鸟类,继续选择特征,确定具体动物
48+
:return: 无
49+
"""
50+
print('该动物是鸟类动物')
51+
print()
52+
print('1羽毛艳丽;2雌雄成对;3乌黑羽毛')
53+
choice = int(input('请继续从上面特征中进行选择'))
54+
if choice == 1:
55+
print('该动物是孔雀')
56+
elif choice == 2:
57+
print('该动物是鸳鸯')
58+
elif choice == 3:
59+
print('该动物是乌鸦')
60+
else:
61+
print('输入无效,无法确定具体动物')
62+
63+
def reptile():
64+
"""
65+
确定是爬行动物,继续选择特征,确定具体动物
66+
:return: 无
67+
"""
68+
print('该动物是爬行动物')
69+
print()
70+
print('1无四肢;2体背腹扁平;3有甲壳')
71+
choice = int(input('请继续从上面特征中进行选择'))
72+
if choice == 1:
73+
print('该动物是蛇')
74+
elif choice == 2:
75+
print('该动物是壁虎')
76+
elif choice == 3:
77+
print('该动物是乌龟')
78+
else:
79+
print('输入无效,无法确定具体动物')
80+
81+
if __name__ == '__main__':
82+
choice = first_feature()
83+
specific_feature(choice)

0 commit comments

Comments
 (0)